﻿/* ======================================================================



=======================================================================*/
var flashObj;
var myTabs;
window.addEvent('domready', function() {
    fixNav.delay(500);
    if ($('flashholder')) {
        var flashObj = new Swiff('./Portals/Blackadders/flash/build/chars.swf', {
            id: 'swiff_test',
            width: 640,
            height: 200,
            container: $('flashholder'),
            params: {},
            events: {
                onLoad: function() { }
            }
        });
    }
    else if ($('partnerFlash')) {
        jiggyTheNav('partnerFlash');
        var flashObj = new Swiff('./Portals/Blackadders/flash/build/Partners.swf', {
            id: 'swiff_test',
            width: 640,
            height: 200,
            container: $('partnerFlash'),
            params: {},
            events: {
                onLoad: function() { }
            }
        });
    }
    else if ($('solicitorFlash')) {
        jiggyTheNav('solicitorFlash');
        var flashObj = new Swiff('./Portals/Blackadders/flash/build/Solicitors.swf', {
            id: 'swiff_test',
            width: 640,
            height: 200,
            container: $('solicitorFlash'),
            params: {},
            events: {
                onLoad: function() { }
            }
        });
    }
    else if ($('directorFlash')) {
        jiggyTheNav('directorFlash');
        var flashObj = new Swiff('./Portals/Blackadders/flash/build/Directors.swf', {
            id: 'swiff_test',
            width: 640,
            height: 200,
            container: $('directorFlash'),
            params: {},
            events: {
                onLoad: function() { }
            }
        });
    }

    if ($('nav_tr')) {
        $$('#nav_tr input').each(function(el, i) {
            if (el.hasClass('inputbox')) {
                el.value = 'search Blackadders';
                el.addEvents({
                    'focus': function() {
                        if (this.value == "search Blackadders") { this.value = ""; }
                    },
                    'blur': function() {
                        if (this.value == "") { this.value = 'search Blackadders'; }
                    }
                });
            }
        });
    }

    if ($$('.sideForm')) {
        var setThatThingLikeItUsedToBe = 0
        if ($$('.sideForm input[type=text]').length > 1) { setThatThingLikeItUsedToBe = 2 }
        $$('.sideForm input[type=text]').each(function(el, i) {
            if (i == setThatThingLikeItUsedToBe) {
                el.value = 'Street Name, Town, etc.';
                el.addEvents({
                    'focus': function() {
                        if (this.value == "Street Name, Town, etc.") { this.value = ""; }
                    },
                    'blur': function() {
                        if (this.value == "") { this.value = 'Street Name, Town, etc.'; }
                    }
                });
            }
        });
    }

    if ($$('.mb').length > 0) {
        //call multiBox
        var initMultiBox = new multiBox({
            mbClass: '.mb', //class you need to add links that you want to trigger multiBox with (remember and update CSS files)
            container: $(document.body), //where to inject multiBox
            descClassName: '', //the class name of the description divs
            path: './Files/', //path to mp3 and flv players
            useOverlay: true, //use a semi-transparent background. default: false;
            maxSize: { w: 600, h: 400 }, //max dimensions (width,height) - set to null to disable resizing
            addDownload: false, //do you want the files to be downloadable?
            pathToDownloadScript: './Scripts/ForceDownload.asp', //if above is true, specify path to download script (classicASP and ASP.NET versions included)
            addRollover: false, //add rollover fade to each multibox link
            addOverlayIcon: false, //adds overlay icons to images within multibox links
            addChain: false, //cycle through all images fading them out then in
            recalcTop: true, //subtract the height of controls panel from top position
            addTips: false//adds MooTools built in 'Tips' class to each element (see: http://mootools.net/docs/Plugins/Tips)
        });
    };

    if ($chk(Fx)) {
        // add hover hover effects to links
        $$('#nav_lhs li').each(function(el, i) { hoverLights(el); });
        //$$('#nav_mainsections li').each(function(el, i) { hoverLightsTop(el); });

        //fix up form elements
        //$(document.body).getElements('input').each(function(el, i) { autoClear(el); });
        //$(document.body).getElements('select').each(function(el, i) { autoClear(el); });
        //$(document.body).getElements('label').each(function(el, i) { assocGlow(el); });

        //	gallery thing
        if ($('property_gallery')) {
            //$$('#property_gallery li').each(function(el, i) { galleryThumbs(el); });

        }
    }
    if ($('tabs')) {
        $$('#tabs li').each(function(el, i) { setupTab(el, i) });

        myTabs = new SlidingTabs('tabs', 'panes');
        /*		
        $('previous').addEvents({
        'mouseenter': function(){this.set('tween', { duration: 400, transition: Fx.Transitions.linear }).tween('opacity', '1');},
        'mouseleave': function(){ this.set('tween', { duration: 400, transition: Fx.Transitions.linear }).tween('opacity', .75);	}
        });
        $('next').addEvents({
        'mouseenter': function(){this.set('tween', { duration: 400, transition: Fx.Transitions.linear }).tween('opacity', '1');},
        'mouseleave': function(){ this.set('tween', { duration: 400, transition: Fx.Transitions.linear }).tween('opacity', .75);	}
        });
        $('previous').setStyles({opacity: .75});
        $('next').setStyles({opacity: .75});
        */
        fixNav.delay(2000);
        /*
        $('previous').addEvent('click', myTabs.previous.bind(myTabs));
        $('next').addEvent('click', myTabs.next.bind(myTabs));
        $('next').setStyle('z-index', '500');
        */

        window.addEvent('resize', myTabs.recalcWidths.bind(myTabs));
    }



    if ($$('.property_results .Sold', '.property_results .UnderOffer', '.property_results .LowerPrice')) {
        //grab images
        var arrImgs = $$('.property_results img.Sold', '.property_results img.UnderOffer', '.property_results img.LowerPrice');

        //loop through each				   
        arrImgs.each(function(el, i) {
            //create div and wrap it around image
            var imgWrap = new Element('div').addClass('imgWrap').wraps(el).setStyles({
                position: 'relative',
                overflow: 'hidden',
                float: 'right',
                width: 185,
                height: 130
            });

            //set html text of span
            if (el.hasClass('Sold')) {
                var myImage = new Asset.image('./portals/blackadders/graphics/sold.png').setStyles({
                    position: 'absolute',
                    left: 0,
                    bottom: 0,
                    zIndex: 999,
                    border: 'none',
                    width: 165,
                    height: 110
                });
            } else if (el.hasClass('UnderOffer')) {
                var myImage = new Asset.image('./portals/blackadders/graphics/underoffer.png').setStyles({
                    position: 'absolute',
                    left: 0,
                    bottom: 0,
                    zIndex: 999,
                    border: 'none',
                    width: 165,
                    height: 110
                });
            } else if (el.hasClass('LowerPrice')) {
                var myImage = new Asset.image('./portals/blackadders/graphics/lowerprice.png').setStyles({
                    position: 'absolute',
                    left: 0,
                    bottom: 0,
                    zIndex: 999,
                    border: 'none',
                    width: 165,
                    height: 110
                });
            };
            myImage.inject(imgWrap, 'bottom');
        });
    };

    if ($('mapPop')) { addMapHover(); }
    /* 	if($('hp_search')){ addSearchHover(); } */
    if ($('feedRotator')) { feedRotator(); }

    //flyout menu
    //declare variable
    var privateClient = $$('#nav_mainsections ul li.PrivateClient ul');
    var privateClientPlus = $$('#nav_mainsections ul li.PrivateClient ul ul');

    var property = $$('#nav_mainsections ul li.Property ul');
    var propertyPlus = $$('#nav_mainsections ul li.Property ul ul');

    var business = $$('#nav_mainsections ul li.Business ul');
    var businessPlus = $$('#nav_mainsections ul li.Business ul ul');

    var court = $$('#nav_mainsections ul li.Court ul');
    var courtPlus = $$('#nav_mainsections ul li.Court ul ul');

    var financial = $$('#nav_mainsections ul li.Financial ul');
    var financialPlus = $$('#nav_mainsections ul li.Financial ul ul');

    //reposition slightly for Safari
    if (Browser.Engine.webkit) {
        //financial
        financial.setStyle('margin-left', '-46px');
        financialPlus.setStyle('margin-left', '0');
    };

    //reposition slightly for Opera
    if (Browser.Engine.presto) {
        //financial
        financial.setStyle('margin-left', '-58px');
        financialPlus.setStyle('margin-left', '0');
    };
});

function fixNav(){

	$('nav_mainsections').setStyle('position', 'relative');
	$('nav_mainsections').setStyle('position', 'absolute');
	$('nav_mainsections').setStyle('z-index', '200');

	/* $('content_region').setStyle('display', 'none'); */
	
	//repeat.delay(500);
}
function repeat(){
	fixNav.delay(1000);
}


var active = 0;
function setupTab(el, i) {
	el.setStyles({ opacity: .75, padding: 18, float: 'left' });
	el.i = i;
	el.addEvents({
		'mouseenter': function(){
		this.hovering = true;
			this.set('tween', { duration: 400, transition: Fx.Transitions.linear }).tween('opacity', '1');
		},
		'mouseleave': function(){
		this.hovering = false;
			if(!this.active){
				this.set('tween', { duration: 400, transition: Fx.Transitions.linear }).tween('opacity', .75);
			}
		},
		'click': function(){
			active = this.i;
		}
	});
}

function checkActive(){
	//alert('checkActive '+active);
	$$('#tabs li').each(function(el, i) { 
		if(active == i) { 
			el.active = true; 
			el.set('tween', { duration: 400, transition: Fx.Transitions.linear }).tween('opacity', '1');
		}
		else{
			el.active = false;
			if(!el.hovering){el.set('tween', { duration: 400, transition: Fx.Transitions.linear }).tween('opacity', .75);}
		}
	
	});
	return active
}
function setActive(id) {
	active = id;
	
	$$('#addedNav a').each(function(el, i) {
		if(i==active){
			el.addClass('active');
		}
		
		else{
			el.removeClass('active');
		}
		
	});
	myTabs.changeTo(active+1);
}
/* ======================================================================

Functions

=======================================================================*/

function jiggyTheNav(ids){
	var tlist = $('tabs').get('html');
	var txt = '<ul id="addedNav">'+tlist+'</ul>';
/* 	alert(tlist); */
	$$('#nav_lhs .active').each(function(el, i) {
		if(i==1){
			el.set('html', el.get('html')+txt);
			reworkList.delay(500);
		}
	});
	
}
function reworkList(){
	$$('#addedNav a').each(function(el, i) {
		el.num = i;
		if(i==0){el.addClass('active');}
		el.addEvents({
			'click': function(e){
				e.stop();
				setActive(this.num);
			}
		});
	});
}


function galleryThumbs(el) {
	//el.getElement('a')
	new Asset.image(el.getElement('a'));
	
	if(!el.hasClass('active')){
	el.setStyles({ opacity: .75 });	
		el.addEvents({
			'mouseenter': function(){
				this.set('tween', { duration: 350, transition: Fx.Transitions.linear }).tween('opacity', '1');
			},
			'mouseleave': function(){
				this.set('tween', { duration: 350, transition: Fx.Transitions.linear }).tween('opacity', .75);
			},
			'click': function(e){
				var dnd = $('property_gallery').hasClass('dnd');
				if(!this.hasClass('active')  &&  !dnd){
					$$('#property_gallery li').each(function(el, i) { 
						if(el.hasClass('active')){
							el.removeClass('active');
							galleryThumbs(el);
						}
					});
					this.addClass('active');
					loadImage(this.getElement('a'));
				}
				e.stop();
				this.removeEvents('mouseleave');
			}
		});
	}
}
function loadImage(url) {
	var cimg = $('image_holder').getElement('img');
	cimg.set('id','removeThis');
	cimg.setStyles({
		position: 'absolute'
	});
	var newdiv = new Element('img').injectInside($('image_holder'));
		
		newdiv.setStyles({
			opacity: 0
		});
		newdiv.set('src',url);
		$('property_gallery').addClass('dnd');
		cimg.set('tween', { 
			duration: 500, 
			transition: Fx.Transitions.linear, 
			'onComplete': function() { 
					
				$('property_gallery').removeClass('dnd');
				$('removeThis').dispose(); 
				newdiv.set('tween', { duration: 500, transition: Fx.Transitions.linear, 'onComplete': function(){  } }).tween('opacity', 1);
			} 
		}).tween('opacity', 1);
		
		
}

var chkd = 0;
function hoverLights(el) {

	if(el.getParent().getParent().get('class') == 'sideForm') {
		
		dummyUpChecks(el);
	}

	if(!el.hasClass('active')) {
	/*
		var newdiv = new Element('div').injectInside(el);
		newdiv.setStyles({
			position: 'absolute',
			left: 0,
			width: 8,
			height: 8,
			background: 'url(./Portals/Blackadders/graphics/lhs_light.jpg) no-repeat',
			margin: '-18px 0px 0px 0px',
			opacity: 0,
			display: 'none'
		});
		
		el.light = newdiv;
		el.setStyles({ opacity: .75 });	
		el.lnk = el.getFirst('a');
		el.lnk.setStyle('font-weight', 'normal');
		el.def = el.lnk.getStyle('background');
		el.addEvents({
			'mouseenter': function(){
				this.light.set('tween', { duration: 400, transition: Fx.Transitions.linear }).tween('opacity', '1');
				this.set('tween', { duration: 400, transition: Fx.Transitions.linear }).tween('opacity', '1');
				 this.lnk.setStyle('background', 'url(./Portals/Blackadders/graphics/lhs_light.jpg) no-repeat'); 
			},
			'mouseleave': function(){
				this.light.set('tween', { duration: 400, transition: Fx.Transitions.linear }).tween('opacity', '0');
				this.set('tween', { duration: 400, transition: Fx.Transitions.linear }).tween('opacity', .75);
				 this.lnk.setStyle('background', this.def);
			}
		});
	
	*/
	}
}

function softerLights(el) {

	if(!el.hasClass('active')) {
		el.setStyles({opacity: .75})
		el.addEvents({
			'mouseenter': function(){
				this.set('tween', { duration: 400, transition: Fx.Transitions.linear }).tween('opacity', '1');
			},
			'mouseleave': function(){
				this.set('tween', { duration: 400, transition: Fx.Transitions.linear }).tween('opacity', .75);
			}
		});
	}
}


function dummyUpChecks(el) {
	el.addEvents({
		'click': function(e){
			e.stop();
			if(this.hasClass('checkSelect')){
				this.addEvents({
					'mouseleave': function(){
						this.light.set('tween', { duration: 400, transition: Fx.Transitions.linear }).tween('opacity', '0');
						this.set('tween', { duration: 400, transition: Fx.Transitions.linear }).tween('opacity', .75);
					}
				});
				this.light.set('tween', { duration: 400, transition: Fx.Transitions.linear }).tween('opacity', '0');
				this.set('tween', { duration: 400, transition: Fx.Transitions.linear }).tween('opacity', .75);
				this.removeClass('checkSelect');
			}
			else{
				this.removeEvents('mouseleave');
				this.addClass('checkSelect');
			}
		}
	});
}

function hoverLightsTop(el) {
	if(!el.hasClass('active')) {
		el.setStyles({ opacity: .75 });	
		el.addEvents({
			'mouseenter': function(){
				this.set('tween', { duration: 150, transition: Fx.Transitions.linear }).tween('opacity', 1);
			},
			'mouseleave': function(){
				this.set('tween', { duration: 150, transition: Fx.Transitions.linear }).tween('opacity', .75);
				}
		});
	}
}

function autoClear(el) {
	el.setStyles({ opacity: .75 });	
	el.addEvents({
		'mouseenter': function(){
			this.set('tween', { duration: 150, transition: Fx.Transitions.linear }).tween('opacity', '1');
			if(this.assoc){this.assoc.set('tween', { duration: 150, transition: Fx.Transitions.linear }).tween('opacity', '1');}
		},
		'focus': function(){
		this.foc = true;
			this.set('tween', { duration: 150, transition: Fx.Transitions.linear }).tween('opacity', '1');
			if(this.assoc){this.assoc.set('tween', { duration: 150, transition: Fx.Transitions.linear }).tween('opacity', '1');}
		},
		'mouseleave': function(){
			if(!this.foc){
				this.set('tween', { duration: 150, transition: Fx.Transitions.linear }).tween('opacity', .75);
				if(this.assoc){this.assoc.set('tween', { duration: 150, transition: Fx.Transitions.linear }).tween('opacity', '.75');}
			}
		},
		'blur': function(){
			this.foc = false;
			this.set('tween', { duration: 150, transition: Fx.Transitions.linear }).tween('opacity', .75);
			if(this.assoc){this.assoc.set('tween', { duration: 150, transition: Fx.Transitions.linear }).tween('opacity', '.75');}
		}
	});
	
	if(el.get('type') == 'text') {
		el.addEvent('focus', function(){
			this.ival = this.value;
			this.value = '';
		});
		el.addEvent('blur', function(){
			if(this.value=='') {
				this.value = this.ival;
			}
		});
	}
}

function assocGlow(el) {
	el.assoc = $(el.get("for"));
	el.assoc.assoc = el;
	el.setStyles({ opacity: .75 });	
	el.addEvents({
		'mouseenter': function(){
			this.set('tween', { duration: 150, transition: Fx.Transitions.linear }).tween('opacity', '1');
			this.assoc.set('tween', { duration: 150, transition: Fx.Transitions.linear }).tween('opacity', '1');
		},
		'mouseleave': function(){
			this.set('tween', { duration: 150, transition: Fx.Transitions.linear }).tween('opacity', .75);
			this.assoc.set('tween', { duration: 150, transition: Fx.Transitions.linear }).tween('opacity', .75);
		}
	});
}

/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

Map Hover Functions

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
function addMapHover(){
	
	$('mapPop').mph = new Fx.Morph($('mapPop'), {duration: 'short', transition: Fx.Transitions.Sine.easeOut});
	$('mapPop').img = $('mapPop').getFirst('img');
	$$('#mapPop ul').each(function(el,i){
		el.fade('hide');	
	});
	$('mapPop').addEvents({
		'mouseenter': function(){
			this.img.fade(0);
			
			$$('#mapPop ul').each(function(el,i){
				el.fade(1);	
			});
			this.mph.start({
			    'height': 380,
			    'width': 308
			});
			$$('#hp_search select').each(function(el, i) { 
				el.fade(0);
			});
			this.over = true
			checkStatus.delay(1000);
		},
		'mouseleave': function(){
			this.img.fade(1);
			
			$$('#mapPop ul').each(function(el,i){
				el.fade(0);	
			});
			this.mph.start({
			    'height': 114,
			    'width': 145
			});
			$$('#hp_search select').each(function(el, i) { 
				el.fade(1);
			});
			this.over = false
		}
	});
}
function checkStatus(){
	if($('mapPop').over == false){
		$('mapPop').mph.start({
		    'height': 114,
		    'width': 145
		});
			$$('#hp_search select').each(function(el, i) { 
				el.fade(1);
			});
	}
}

function addSearchHover(){
	
	$('hp_search').mph = new Fx.Morph($('hp_search'), {duration: 'short', transition: Fx.Transitions.Sine.easeOut});
	
		$$('#hp_search select').each(function(el, i) { 
			el.addEvent('focus', function(){
					$('hp_search').over = true;
				});
		});
	$('hp_search').addEvents({
		'mouseenter': function(){
			this.mph.start({
			    'height': 240,
			    'width': 308
			});
			this.over = true
			checkSearchStatus.delay(1000);
		},
		'mouseleave': function(){
			this.over = false;
			checkSearchStatus.delay(1000);
		}
	});
}
function checkSearchStatus(){
	if($('hp_search').over == false){
		$('hp_search').mph.start({
		    'height': 240,
		    'width': 145
		});
	}
}

/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

Feed Rotator

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
var feedItems = new Array();
var count = 0;
function feedRotator(){
	//$('feedRotator').setStyle('position','relative');
	var img = $('feedRotator').getElement('img')
	img.setStyle('position', 'absolute');
	img.setStyle('top', '28px');
	//feedItems.push(img);
	$$('#feedRotator .newsItem').each(function(el, i) { 
		el.setStyle('position', 'absolute');
		el.setStyle('top', '116px');
		el.setStyle('opacity', 0);
		var desc = el.getElement('p');
		//var sd = desc.get('text').substring(0,60)
		var sd = desc.get('text').split(' ');
		var str = '';
		if(sd.length>8){
			for(var i=0;i<8;i++){
				str = str+' '+sd[i];
			}
		}
		else{str = desc.get('text');}
		desc.set('text', str+'...');
		var lnk = el.getElement('a')
		lnk.setProperty('target', '_blank');

		el.mph = new Fx.Morph(el, {duration: 'normal', transition: Fx.Transitions.Sine.easeOut});
		feedItems.push(el);
	});
	crossFade.delay(2500);
}
function crossFade(){
	$('feedRotator').getElement('img').fade('.1');
	feedItems[count].mph.start({
		'top': '-116px',
		'opacity': 0
	});
	count++;
	if(count>=feedItems.length){count = 0;}
	feedItems[count].setStyle('top', '116px');
	if(Browser.Engine.trident){
		feedItems[count].mph.start({
			'top': '30px',
			'opacity': 1
		});
	}
	else{
		feedItems[count].mph.start({
			'top': '20px',
			'opacity': 1
		});
	}

	crossFade.delay(5000);
}

