
// JavaScript Document
$(document).ready(function(){
	   onpagereloaded();
//	get_map_cords();
   });




function onpagereloaded() {

	$('.fademe').css("opacity","0.2");
	$("div#desc").queue(function (){
		if(jQuery.browser.msie){
			$("div#desc").children().css("display","none");
			$(this).dequeue();
		}else{
			$(this).dequeue();
		}
	});
	$("div#desc").css("height","0px").css("opacity","0.7").animate({
			height:"75px"
			},1000, "swing", function () {
				$("div#desc").queue(function (){
					if(jQuery.browser.msie){
						$("div#desc").children().css("display","block");
						$(this).dequeue();
					}else{
						$(this).dequeue();
					}
				});
			});
	setTimeout('dodrawer();',1500);
	
	
	$("#bottom_nav a img").not(".active").fadeTo(1,0.7).mouseover(function () {
		$(this).fadeTo(500,1).mouseout(function () {
                            $(this).stop();
                            $(this).fadeTo(500,0.7);
		 });
	});
//	$('.lnav a').hide();
	$('.form').fadeTo(1,0.0,function (){
		$(this).contents().fadeTo(400,0);
	}).css("display","block").fadeTo(800,0.5,function (){
		$(this).contents().fadeTo(400,1);										 
	})
	$('#wedding_shows').change(function () {
		wedding_shows_loader($(this));
	});
	$('#price_lists').change(function () {
		price_lists_loader($(this));
	});

	var myLocation = window.location.toString();
	myLocation = myLocation.replace("http://www.youngs-hire.co.uk",'');
	$('#left_container a').each(function(){
		var hrefLocation = $(this).attr('href');
		if(strfound(myLocation, hrefLocation)){$(this).attr('style','color:#EEEEEE;');};
	});
	
	
	onsemireloaded();
	pageready();
}
function dodrawer(){
	$("div#rightdraw").css('width',"424px").animate({
				width:"20px"
				},2000, "swing");
		$("div#rightdraw").bind("mouseenter",function(){
			var timer = 2000*((444-$("div#rightdraw").width())/424);
			$('div#content_2').stop(true,false).fadeTo(timer,0.5);
			$("div#rightdraw").stop(true,false).animate({width:"424px"},timer, "swing");
		}).bind("mouseleave",function(){
			var timer = 2000*(($("div#rightdraw").width()-20)/404);
			$('div#content_2').stop(true,false).fadeTo(timer,1);
			$("div#rightdraw").stop(true,false).animate({width:"20px"},timer, "swing");
		});
}


var x={};

function pageready() {

	$('#price_lists').each(function (){
		price_lists_loader($('#price_lists'));
	});
	$('#wedding_shows').each(function (){
		wedding_shows_loader($('#wedding_shows'));
	});
	$('#advicebox .instruction').hide().each(function (intIndex){
                                                    i=intIndex+1;
                                                    x[i] = $(this).html();
                                                    if(i==2){
                                                        loadadvice(1);
                                                    }
												});

}

function onsemireloaded() {

	   $(".email").each(function (i){
			var email = $(this).html();
			$(this).html("<a href=\"mailto:"+email+"@srghouse.co.uk\">"+email+"@srghouse.co.uk</a>");
			  	});
	   $(".ext").click(function () {
				window.open(this.href);
				return false;
			});
        $('form#order').submit(function(){
            var tested = true;
            $('form#order select').each(function(){
                if($(this).val()=="false"){
                    $(this).removeClass('valid').addClass('invalid');
                    tested = false;
                }else{
                    $(this).removeClass('invalid').addClass('valid');
                }
                return true;
            });
            return tested;
        });
        $('form#details').submit(function(){
            var tested = true;
            var emailRegxp = /^([\w]+)(.[\w]+)*@([\w]+)(.[\w]{2,3}){1,2}$/;
            $('form#details select').each(function(){
                if($(this).val()=="false"){
                    $(this).removeClass('valid').addClass('invalid');
                    tested = false;
                }else{
                    $(this).removeClass('invalid').addClass('valid');
                }
                return true;
            });
            $('form#details input').each(function(){
                if($(this).val()==""){
                    $(this).removeClass('valid').addClass('invalid');
                    tested = false;
                }else if(($(this).attr('name')=="email")&&(emailRegxp.test($(this).val()) != true)){
                    $(this).removeClass('valid').addClass('invalid');
                    tested = false;
                }else{
                    $(this).removeClass('invalid').addClass('valid');
                }
                return true;
            });
            return tested;
        });
        $('form#brochure').submit(function(){
            var tested = true;
            var emailRegxp = /^([\w]+)(.[\w]+)*@([\w]+)(.[\w]{2,3}){1,2}$/;
            $('form#brochure select').each(function(){
                if($(this).val()=="false"){
                    $(this).removeClass('valid').addClass('invalid');
                    tested = false;
                }else{
                    $(this).removeClass('invalid').addClass('valid');
                }
                return true;
            });
            $('form#brochure input').each(function(){
                if($(this).val()==""){
                    $(this).removeClass('valid').addClass('invalid');
                    tested = false;
                }else if(($(this).attr('name')=="email")&&(emailRegxp.test($(this).val()) != true)){
                    $(this).removeClass('valid').addClass('invalid');
                    tested = false;
                }else{
                    $(this).removeClass('invalid').addClass('valid');
                }
                return true;
            });
            $('form#brochure textarea').each(function(){
                if($(this).val()==""){
                    $(this).removeClass('valid').addClass('invalid');
                    tested = false;
                }else{
                    $(this).removeClass('invalid').addClass('valid');
                }
                return true;
            });
            return tested;
        });
        $('form#payment-transfer').submit(function(){
            if($('input#conditions').is(":checked")){
                return true;
            }
            alert('Please agree to the terms and conditions to proceed!');
            return false;
        });
        $('form#payment').submit();

        $(".cycleMe").cycle();

}

function price_lists_loader(obj) {
		var y={};
		var x = "/price_lists/"+obj.val();
		$.get(x, function(data){
				y['plhtml'] = data;
			});
            if($('#price_lists_table table').hasClass("hidemequick")){
                $('#price_lists_table table').remove();
            }
		$('#price_lists_table').fadeOut('slow');
		$('#price_lists_table').queue(function(){
			$(this).html(y['plhtml']);
			onsemireloaded();
			$(this).dequeue();
		});
		$('#price_lists_table').fadeIn('slow');

}

function wedding_shows_loader(obj) {
		var y={};
		var x = "/wedding_shows/"+obj.val();
		$.get(x, function(data){
				y['wshtml'] = data;
			});
		$('#wed_show_table').fadeOut('slow');
		$('#wed_show_table').queue(function(){
			$(this).html(y['wshtml']);
			onsemireloaded();
			$(this).dequeue();
		});
		$('#wed_show_table').fadeIn('slow');

}

function get_map_cords() {
	
	var imfile = $('#map').attr('src');
	$('#map').replaceWith('<form id="map" action="#" method="GET"><input type="image" src="'+imfile+' /></form>');
}


function loadadvice(i){
    $('#advicebox .instruction').remove();
    var mybuttons = "";
    var il = i-1;
    var ip = i+1;
    if(x[il]){
        mybuttons = mybuttons+'<a class="back" href="javascript:loadadvice('+il+');">&lt; back</a>';
    }
    if(x[ip]){
        mybuttons = mybuttons+'<a class="next" href="javascript:loadadvice('+ip+');">next &gt;</a>';
    }
    $('#advicebox').append('<div class="instruction">'+x[i]+''+mybuttons+'</div>');
}

(function($) {
	$.fn.iecFadeIn = function(speed, callback) {
		$(this).fadeIn(speed, function() {
			if(jQuery.browser.msie)
				$(this).get(0).style.removeAttribute('filter');
			if(callback != undefined)
				callback();
		});
	};
	$.fn.iecFadeOut = function(speed, callback) {
		$(this).fadeOut(speed, function() {
			if(jQuery.browser.msie)
				$(this).get(0).style.removeAttribute('filter');
			if(callback != undefined)
				callback();
		});
	};
})(jQuery);


// {{{ strrpos
function strfound( haystack, needle, offset){
	// Find position of last occurrence of a char in a string
	// 
	// +    discuss at: http://kevin.vanzonneveld.net/techblog/article/javascript_equivalent_for_phps_strrpos/
	// +       version: 810.819
	// +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
	// +   bugfixed by: Onno Marsman
	// *     example 1: strrpos('Kevin van Zonneveld', 'e');
	// *     returns 1: 16
	var i = (haystack+'').lastIndexOf( needle, offset ); // returns -1
	return i >= 0 ? true : false;
}// }}}
    

// JavaScript Document
function set_location(placename,details){
	
	var curhtml = '<h3>'+placename+'</h3><img src="/images/img/storelocator/suitsyou_logo.jpg" alt="suitsyou logo" /><p>'+details+'</p>';
	document.getElementById('address').innerHTML=curhtml;
	
};

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function JustSoPicWindow(imageName,imageWidth,imageHeight,alt,bgcolor,hugger,hugMargin) {
// by E Michael Brandt of ValleyWebDesigns.com - Please leave these comments intact.
// version 3.0.4  

	if (bgcolor=="") {
		bgcolor="#FFFFFF";
	}
	var adj=10
	var w = screen.width;
	var h = screen.height;
	var byFactor=1;

	if(w<740){
	  var lift=0.90;
	}
	if(w>=740 & w<835){
	  var lift=0.91;
	}
	if(w>=835){
	  var lift=0.93;
	}
	if (imageWidth>w){	
	  byFactor = w / imageWidth;			
	  imageWidth = w;
	  imageHeight = imageHeight * byFactor;
	}
	if (imageHeight>h-adj){
	  byFactor = h / imageHeight;
	  imageWidth = (imageWidth * byFactor);
	  imageHeight = h; 
	}
	   
	var scrWidth = w-adj;
	var scrHeight = (h*lift)-adj;

	if (imageHeight>scrHeight){
  	  imageHeight=imageHeight*lift;
	  imageWidth=imageWidth*lift;
	}

	var posLeft=0;
	var posTop=0;

	if (hugger == "hug image"){
	  if (hugMargin == ""){
	    hugMargin = 0;
	  }
	  var scrHeightTemp = imageHeight - 0 + 2*hugMargin;
	  if (scrHeightTemp < scrHeight) {
		scrHeight = scrHeightTemp;
	  } 
	  var scrWidthTemp = imageWidth - 0 + 2*hugMargin;
	  if (scrWidthTemp < scrWidth) {
		scrWidth = scrWidthTemp;
	  }
	  
	  if (scrHeight<100){scrHeight=100;}
	  if (scrWidth<100){scrWidth=100;}

	  posTop =  ((h-(scrHeight/lift)-adj)/2);
	  posLeft = ((w-(scrWidth)-adj)/2);
 	}

	if (imageHeight > (h*lift)-adj || imageWidth > w-adj){
		imageHeight=imageHeight-adj;
		imageWidth=imageWidth-adj;
	}
	posTop = parseInt(posTop);
	posLeft = parseInt(posLeft);		
	scrWidth = parseInt(scrWidth); 
	scrHeight = parseInt(scrHeight);
	
	var agt=navigator.userAgent.toLowerCase();
	if (agt.indexOf("opera") != -1){
	  var args= new Array();
	  args[0]='parent';
	  args[1]=imageName;
	  var i ; document.MM_returnValue = false;
	  for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
	} else {
	newWindow = window.open("/html/vwd_justso.php","newWindow","width="+scrWidth+",height="+scrHeight+",left="+posLeft+",top="+posTop);
	newWindow.document.open();
	newWindow.document.write('<html><title>'+alt+'</title><body leftmargin="0" topmargin="0" marginheight="0" marginwidth="0" bgcolor='+bgcolor+' onBlur="self.close()" onClick="self.close()">');  
	newWindow.document.write('<table width='+imageWidth+' border="0" cellspacing="0" cellpadding="0" align="center" height='+scrHeight+' ><tr><td>');
	newWindow.document.write('<img src="'+imageName+'" width='+imageWidth+' height='+imageHeight+' alt="Click screen to close" >'); 
	newWindow.document.write('</td></tr></table></body></html>');
	newWindow.document.close();
	newWindow.focus();
	}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}


function MM_nbGroup(event, grpName) { //v6.0
  var i,img,nbArr,args=MM_nbGroup.arguments;
  if (event == "init" && args.length > 2) {
    if ((img = MM_findObj(args[2])) != null && !img.MM_init) {
      img.MM_init = true; img.MM_up = args[3]; img.MM_dn = img.src;
      if ((nbArr = document[grpName]) == null) nbArr = document[grpName] = new Array();
      nbArr[nbArr.length] = img;
      for (i=4; i < args.length-1; i+=2) if ((img = MM_findObj(args[i])) != null) {
        if (!img.MM_up) img.MM_up = img.src;
        img.src = img.MM_dn = args[i+1];
        nbArr[nbArr.length] = img;
    } }
  } else if (event == "over") {
    document.MM_nbOver = nbArr = new Array();
    for (i=1; i < args.length-1; i+=3) if ((img = MM_findObj(args[i])) != null) {
      if (!img.MM_up) img.MM_up = img.src;
      img.src = (img.MM_dn && args[i+2]) ? args[i+2] : ((args[i+1])? args[i+1] : img.MM_up);
      nbArr[nbArr.length] = img;
    }
  } else if (event == "out" ) {
    for (i=0; i < document.MM_nbOver.length; i++) {
      img = document.MM_nbOver[i]; img.src = (img.MM_dn) ? img.MM_dn : img.MM_up; }
  } else if (event == "down") {
    nbArr = document[grpName];
    if (nbArr)
      for (i=0; i < nbArr.length; i++) { img=nbArr[i]; img.src = img.MM_up; img.MM_dn = 0; }
    document[grpName] = nbArr = new Array();
    for (i=2; i < args.length-1; i+=2) if ((img = MM_findObj(args[i])) != null) {
      if (!img.MM_up) img.MM_up = img.src;
      img.src = img.MM_dn = (args[i+1])? args[i+1] : img.MM_up;
      nbArr[nbArr.length] = img;
  } }
}


// begin absolutely positioned scrollable area object scripts 
// Extension developed by David G. Miles 
// Original Scrollable Area code developed by Thomas Brattli 
function verifyCompatibleBrowser(){ 
    this.ver=navigator.appVersion 
    this.dom=document.getElementById?1:0 
    this.ie5=(this.ver.indexOf("MSIE 5")>-1 && this.dom)?1:0; 
    this.ie4=(document.all && !this.dom)?1:0; 
    this.ns5=(this.dom && parseInt(this.ver) >= 5) ?1:0; 
 
    this.ns4=(document.layers && !this.dom)?1:0; 
    this.bw=(this.ie5 || this.ie4 || this.ns4 || this.ns5) 
    return this 
} 
bw=new verifyCompatibleBrowser() 
 
 
var speed=50 
 
var loop, timer 
 
function ConstructObject(obj,nest){ 
    nest=(!nest) ? '':'document.'+nest+'.' 
    this.el=bw.dom?document.getElementById(obj):bw.ie4?document.all[obj]:bw.ns4?eval(nest+'document.'+obj):0; 
    this.css=bw.dom?document.getElementById(obj).style:bw.ie4?document.all[obj].style:bw.ns4?eval(nest+'document.'+obj):0; 
    this.scrollHeight=bw.ns4?this.css.document.height:this.el.offsetHeight 
    this.clipHeight=bw.ns4?this.css.clip.height:this.el.offsetHeight 
    this.up=MoveAreaUp;this.down=MoveAreaDown; 
    this.MoveArea=MoveArea; this.x; this.y; 
    this.obj = obj + "Object" 
    eval(this.obj + "=this") 
    return this 
} 
function MoveArea(x,y){ 
    this.x=x;this.y=y 
    this.css.left=this.x 
    this.css.top=this.y 
} 
 
function MoveAreaDown(move){ 
	if(this.y>-this.scrollHeight+objContainer.clipHeight){ 
    this.MoveArea(0,this.y-move) 
    if(loop) setTimeout(this.obj+".down("+move+")",speed) 
	} 
} 
function MoveAreaUp(move){ 
	if(this.y<0){ 
    this.MoveArea(0,this.y-move) 
    if(loop) setTimeout(this.obj+".up("+move+")",speed) 
	} 
} 
 
function PerformScroll(speed){ 
	if(initialised){ 
		loop=true; 
		if(speed>0) objScroller.down(speed) 
		else objScroller.up(speed) 
	} 
} 
 
function CeaseScroll(){ 
    loop=false 
    if(timer) clearTimeout(timer) 
} 
var initialised; 
function InitialiseScrollableArea(){ 
    objContainer=new ConstructObject('divContainer') 
    objScroller=new ConstructObject('divContent','divContainer') 
    objScroller.MoveArea(0,0) 
    objContainer.css.visibility='visible' 
    initialised=true; 
} 
// end absolutely positioned scrollable area object scripts 

/*	
function loadPage(x){
	var domain = document.domain;
	var x = x.replace("http://"+domain+"/",'');
	x = "/partial/"+x;
	x = x.replace("ial//","ial/");
	$.get(x, function(data){
    		data = data+"\n<script>\n\t\t<!--\nafterpagereset();\n-->\n</s"+"cript>";
			y['html'] = data;
	});
	$('#content_2').fadeOut('slow');
	$('#content_2').queue(function(){
		$(this).html(y['html']);
		$(this).dequeue();
	});
	$('#content_2').fadeIn('slow');
};

function afterpagereset(){
	$('#content_2 a').not("a.ext").click(function(){
		loadPage($(this).attr('href'));
		return false;
	});
	$('#content_2 a.ext').click(function(){
		window.open($(this).attr('href'));
		return false;
	});
};


$(document).ready(function (e) {
	$(e).pngFix();
});

$(document).ready(function() {
  $("#content_2").hide().fadeIn(3000);
});

$(document).ready(function(){
	$('ab').not("a.ext").click(function(){
		loadPage($(this).attr('href'));
		return false;
	});
	$('a.ext').click(function(){
		window.open($(this).attr('href'));
		return false;
	});
});
*/
