jQuery("#slider").easySlider({});
//jQuery("#doCase").lightbox({src:'http://duffy.amd.ict/wp-content/themes/duffy/images/logo.gif'});
function show_player(name,file){
		var id = jQuery("#dialog");
		//alert(this.href);
		jQuery(id).html("<div class='defaultCase'><table border='0'cellpadding='0'cellspacing='0'width='100%'class='caseHeader'><tr><td><h4>"+name+"</h4></td><td valign='top'class='close'><a href='javascript:void(0);' class='close'>close</a></td></tr>"+
			'<tr><td colspan="2" align="center" style="padding-top:20px;"><object type="application/x-shockwave-flash" data="'+theme_url+'/player_mp3.swf" width="400" height="40">'+
			'<param name="movie" value="'+theme_url+'/player_mp3.swf" />'+
			'<param name="FlashVars" value="mp3='+theme_url+'/'+file+'.mp3&amp;bgcolor1=ffffff&amp;bgcolor2=cccccc&amp;buttoncolor=999999&amp;buttonovercolor=0&amp;slidercolor1=cccccc&amp;slidercolor2=999999&amp;sliderovercolor=666666&amp;textcolor=0" />'+
			'</object></td></tr></table>'+
			"</div>");
		jQuery('.close').click(function (e) {
				e.preventDefault();
				jQuery('#lightbox-overlay').hide();
				jQuery('.window').hide();
		});
		init_shadow();
}
function show_map(e,el){
		var id = jQuery("#dialog");
		//alert(this.href);
		init_shadow();
		jQuery('#dialog').css({'width':835,'height':543});
		var winH = jQuery(window).height();
		var winW = jQuery(window).width();
		jQuery(id).css('top',  winH/2-jQuery(id).height()/2);
		jQuery(id).css('left', winW/2-jQuery(id).width()/2);

		jQuery(id).html("<table border='0'cellpadding='0'cellspacing='0'width='100%'class='caseHeader'><tr><td>&nbsp;</td><td valign='top'class='close'><a href='javascript:void(0);' class='close'>close</a></td></tr>"+
			'<tr><td colspan="2"><img src="'+el.href+'">'+
			'</td></tr></table>'+
			"");
		jQuery('.close').click(function (e) {
				e.preventDefault();
				jQuery('#lightbox-overlay').hide();
				jQuery('.window').hide();
				jQuery('#dialog').css({'width':716});
		});
		
}


jQuery(document).ready(function() {	
	
	//select all the a tag with name equal to modal
	jQuery('[name=map]').click(function(e){e.preventDefault();show_map(e,this);})
	jQuery('#direction').click(function(e){e.preventDefault();show_direction(e,this);})
	jQuery('#doCase').click(function(e) {
		//Cancel the link behavior
		e.preventDefault();
		
		//Get the A tag
		var id = jQuery("#dialog");
		jQuery(id).html('');
		jQuery(id).load(site_url+"/do_i_have_a_case.php?type=form",null,function(){
				jQuery('.close').click(function (e) {
				e.preventDefault();
				jQuery('#lightbox-overlay').hide();
				jQuery('.window').hide();
			});	
			jQuery('.dialogScroll').css({'height':jQuery(window).height()-230});
			jQuery('#print').click(function(){
				document.forms['do_i_have'].target="_balnk";
				document.forms['do_i_have'].action=site_url+"/do_i_have_a_case.php?type=print";
			});
			jQuery('#print_blank').click(function(){
				document.location.href=site_url+"/do_i_have_a_case.php?type=print_blank";
			});
			jQuery('#submit').click(function(){
				document.forms['do_i_have'].onsubmit=function(){return false;}
				var params=new Array();
				for(i=0;i<document.forms['do_i_have'].elements.length;i++){
					if(document.forms['do_i_have'].elements[i].type.toUpperCase()=='RADIO'&&!document.forms['do_i_have'].elements[i].checked)continue;
					params[params.length]=document.forms['do_i_have'].elements[i].name+"="+document.forms['do_i_have'].elements[i].value;
				}
				//;
				 jQuery.ajax({
				   type: "POST",
				   url: site_url+"/do_i_have_a_case.php?type=send",
				   data: params.join('&'),
				   success: function(msg){
					jQuery('#lightbox-overlay').hide();
					jQuery('.window').hide();
					//alert( "sended: " + msg );
				   }
				 });

			});
				var pos=0;
				var k=5;
				var st=null;
				var h1=jQuery('.dialogScroll').height();
				var h2=jQuery('.dialogScrollable').height();

				jQuery("#scrollUpd").mousedown(function(){
					if(pos+k>0)return;
					k=Math.abs(k);
					st=setInterval(movePosit,10);
				});
				jQuery("#scrollUpd").mouseup(function(){
					clearInterval(st);
				});
				jQuery("#scrollUpd").mouseout(function(){
					clearInterval(st);
				});
				jQuery("#scrollDownd").mouseout(function(){
					clearInterval(st);
				});
				jQuery("#scrollDownd").mouseup(function(){
					clearInterval(st);
				});

				jQuery("#scrollDownd").mousedown(function(){
					if(h1-h2>pos)return;
					k=-Math.abs(k);
					st=setInterval(movePosit,10);
					});
				function movePosit(){
					pos+=k;
					if(pos+k>0||h1-h2>pos)
					{
						clearInterval(st);
						return;
					}
					jQuery('.dialogScrollable').css({'margin-top':pos});
				}
				Custom.init();
				jQuery("#legal").click(function(e){
					e.preventDefault();
					disclaimer_init(this.href);
				});
		});
		init_shadow();

	});
	//if mask is clicked
	jQuery('#lightbox-overlay').click(function () {
		jQuery(this).hide();
		jQuery('.window').hide();
		jQuery('#dialog').css({'width':716});
	});			
	var pos=0;
	var k=2;
	var st=null;
	var h1=jQuery('.scrollContainer').height();
	var h2=jQuery('.scrollable').height();

	if(h1>h2||!h1){
		jQuery('.scrollButtons').hide();
	}
	jQuery("#scrollUp").mousedown(function(){
		if(pos+k>0)return;
		k=Math.abs(k);
		st=setInterval(movePosit,10);
	});
	jQuery("#scrollUp").mouseup(function(){
		clearInterval(st);
	});
	jQuery("#scrollUp").mouseout(function(){
		clearInterval(st);
	});
	jQuery("#scrollDown").mouseout(function(){
		clearInterval(st);
	});
	jQuery("#scrollDown").mouseup(function(){
		clearInterval(st);
	});

	jQuery("#scrollDown").mousedown(function(){
		if(h1-h2>pos)return;
		k=-Math.abs(k);
		st=setInterval(movePosit,10);
		});
	function movePosit(){
		pos+=k;
		if(pos+k>0||h1-h2>pos)
		{
			clearInterval(st);
			return;
		}
		jQuery('.scrollable').css({'margin-top':pos});
	}
	legalcommunity_init();
	
});
var checkboxHeight = "25";
var radioHeight = "25";
var selectWidth = "190";

/* No need to change anything after this */

document.write('<style type="text/css">input.styled { display: none; } select.styled { position: relative; width: ' + selectWidth + 'px; opacity: 0; filter: alpha(opacity=0); z-index: 5; }</style>');

var Custom = {
	init: function() {
		var inputs = document.getElementsByTagName("input"), span = Array(), textnode, option, active;
		for(a = 0; a < inputs.length; a++) {
			if((inputs[a].type == "checkbox" || inputs[a].type == "radio") && inputs[a].className == "styled") {
				span[a] = document.createElement("span");
				span[a].className = inputs[a].type;

				if(inputs[a].checked == true) {
					if(inputs[a].type == "checkbox") {
						position = "0 -" + (checkboxHeight*2) + "px";
						span[a].style.backgroundPosition = position;
					} else {
						position = "0 -" + (radioHeight*2) + "px";
						span[a].style.backgroundPosition = position;
					}
				}
				inputs[a].parentNode.insertBefore(span[a], inputs[a]);
				inputs[a].onchange = Custom.clear;
				span[a].onmousedown = Custom.pushed;
				span[a].onmouseup = Custom.check;
				document.onmouseup = Custom.clear;
			}
		}
		inputs = document.getElementsByTagName("select");
		for(a = 0; a < inputs.length; a++) {
			if(inputs[a].className == "styled") {
				option = inputs[a].getElementsByTagName("option");
				active = option[0].childNodes[0].nodeValue;
				textnode = document.createTextNode(active);
				for(b = 0; b < option.length; b++) {
					if(option[b].selected == true) {
						textnode = document.createTextNode(option[b].childNodes[0].nodeValue);
					}
				}
				span[a] = document.createElement("span");
				span[a].className = "select";
				span[a].id = "select" + inputs[a].name;
				span[a].appendChild(textnode);
				inputs[a].parentNode.insertBefore(span[a], inputs[a]);
				inputs[a].onchange = Custom.choose;
			}
		}
	},
	pushed: function() {
		element = this.nextSibling;
		if(element.checked == true && element.type == "checkbox") {
			this.style.backgroundPosition = "0 -" + checkboxHeight*3 + "px";
		} else if(element.checked == true && element.type == "radio") {
			this.style.backgroundPosition = "0 -" + radioHeight*3 + "px";
		} else if(element.checked != true && element.type == "checkbox") {
			this.style.backgroundPosition = "0 -" + checkboxHeight + "px";
		} else {
			this.style.backgroundPosition = "0 -" + radioHeight + "px";
		}
	},
	check: function() {
		element = this.nextSibling;
		if(element.checked == true && element.type == "checkbox") {
			this.style.backgroundPosition = "0 0";
			element.checked = false;
		} else {
			if(element.type == "checkbox") {
				this.style.backgroundPosition = "0 -" + checkboxHeight*2 + "px";
			} else {
				this.style.backgroundPosition = "0 -" + radioHeight*2 + "px";
				group = this.nextSibling.name;
				inputs = document.getElementsByTagName("input");
				for(a = 0; a < inputs.length; a++) {
					if(inputs[a].name == group && inputs[a] != this.nextSibling) {
						inputs[a].previousSibling.style.backgroundPosition = "0 0";
					}
				}
			}
			element.checked = true;
		}
	},
	clear: function() {
		inputs = document.getElementsByTagName("input");
		for(var b = 0; b < inputs.length; b++) {
			if(inputs[b].type == "checkbox" && inputs[b].checked == true && inputs[b].className == "styled") {
				inputs[b].previousSibling.style.backgroundPosition = "0 -" + checkboxHeight*2 + "px";
			} else if(inputs[b].type == "checkbox" && inputs[b].className == "styled") {
				inputs[b].previousSibling.style.backgroundPosition = "0 0";
			} else if(inputs[b].type == "radio" && inputs[b].checked == true && inputs[b].className == "styled") {
				inputs[b].previousSibling.style.backgroundPosition = "0 -" + radioHeight*2 + "px";
			} else if(inputs[b].type == "radio" && inputs[b].className == "styled") {
				inputs[b].previousSibling.style.backgroundPosition = "0 0";
			}
		}
	},
	choose: function() {
		option = this.getElementsByTagName("option");
		for(d = 0; d < option.length; d++) {
			if(option[d].selected == true) {
				document.getElementById("select" + this.name).childNodes[0].nodeValue = option[d].childNodes[0].nodeValue;
			}
		}
	}
}


function legalcommunity_init(){
	jQuery('#dialogs a,#legal_bot,#dialogs_bot a').click(function(e) {
		e.preventDefault();
		var id = jQuery("#dialog");
		jQuery(id).html('');
		jQuery(id).load(this.href,null,function(){
			jQuery('.close').click(function (e) {
				e.preventDefault();
				jQuery('#lightbox-overlay').hide();
				jQuery('.window').hide();
			});	
			var sizescroll=parseInt(jQuery('#dialog').css('height'))-jQuery('.dialogScroll').position().top-35;
			jQuery('.dialogScroll').css({'height':sizescroll});//jQuery(window).height()-530
				var pos=0;
				var k=5;
				var st=null;
				var h1=jQuery('.dialogScroll').height();
				var h2=jQuery('.dialogScrollable').height();
				
				jQuery("#scrollUpd").mousedown(function(){
					if(pos+k>0)return;
					k=Math.abs(k);
					st=setInterval(movePosit,10);
				});
				jQuery("#scrollUpd").mouseup(function(){
					clearInterval(st);
				});
				jQuery("#scrollUpd").mouseout(function(){
					clearInterval(st);
				});
				jQuery("#scrollDownd").mouseout(function(){
					clearInterval(st);
				});
				jQuery("#scrollDownd").mouseup(function(){
					clearInterval(st);
				});

				jQuery("#scrollDownd").mousedown(function(){
					if(h1-h2>pos+50)return;
					k=-Math.abs(k);
					st=setInterval(movePosit,10);
					});
				function movePosit(){
					pos+=k;
					if(pos+k>0||(h1-h2>pos+50&&k<0))
					{
						clearInterval(st);
						return;
					}
					old_pos=pos;
					jQuery('.dialogScrollable').css({'margin-top':pos});
				}
				var old_pos=0;
				jQuery.jumpto=function(to){
					pos=-jQuery('[name='+to+']').position().top+388+old_pos;
					old_pos=pos;
					jQuery('.dialogScrollable').css({'margin-top':pos});
				}
				Custom.init();
		});
		init_shadow();
	
	});
}
function init_shadow(){
		var id = jQuery("#dialog");
		var maskHeight = jQuery(document).height();
		var maskWidth = jQuery(window).width();
	
		//Set heigth and width to mask to fill up the whole screen
		jQuery('#lightbox-overlay').css({'width':maskWidth,'height':maskHeight});
		jQuery('#dialog').css({'height':jQuery(window).height()-100});
		
		//transition effect		
		jQuery('#lightbox-overlay').fadeIn(1000);	
		jQuery('#lightbox-overlay').fadeTo("slow",0.8);	
	
		//Get the window height and width
		var winH = jQuery(window).height();
		var winW = jQuery(window).width();
              
		//Set the popup window to center
		jQuery(id).css('top',  winH/2-jQuery(id).height()/2);
		jQuery(id).css('left', winW/2-jQuery(id).width()/2);
	
		//transition effect
		jQuery(id).fadeIn(2000); 

}
function disclaimer_init(href){
	var modal=jQuery('#modal_dialog');
	jQuery(modal).css('height',jQuery('#dialog').css('height'));
	jQuery(modal).css('width',jQuery('#dialog').css('width'));
	jQuery(modal).css('left',jQuery('#dialog').css('left'));
	jQuery(modal).css('top',jQuery('#dialog').css('top'));
	jQuery(modal).show();
		jQuery(modal).load(href,null,function(){
			jQuery('.close').click(function (e) {
				e.preventDefault();
				jQuery(modal).hide();
			});	
			jQuery('#dialogScroll').css({'height':jQuery(window).height()-180});
				var pos=0;
				var k=5;
				var st=null;
				var h1=jQuery('#dialogScroll').height();
				var h2=jQuery('#dialogScrollable').height();
				
				jQuery("#modal_dialog #scrollUpd").mousedown(function(){
					if(pos+k>0)return;
					k=Math.abs(k);
					st=setInterval(movePosit,10);
				});
				jQuery("#modal_dialog #scrollUpd").mouseup(function(){
					clearInterval(st);
				});
				jQuery("#modal_dialog #scrollUpd").mouseout(function(){
					clearInterval(st);
				});
				jQuery("#modal_dialog #scrollDownd").mouseout(function(){
					clearInterval(st);
				});
				jQuery("#modal_dialog #scrollDownd").mouseup(function(){
					clearInterval(st);
				});

				jQuery("#modal_dialog #scrollDownd").mousedown(function(){
					if(h1-h2>pos+50)return;
					k=-Math.abs(k);
					st=setInterval(movePosit,10);
					});
				function movePosit(){
					pos+=k;
					if(pos+k>0||(h1-h2>pos+50&&k<0))
					{
						clearInterval(st);
						return;
					}
					jQuery('#dialogScrollable').css({'margin-top':pos});
				}
	});
}
function show_direction(e,el){
			var id = jQuery("#dialog");
		//alert(this.href);
		init_shadow();
		var frameheight=parseInt(jQuery('#dialog').css('height'))-20;
		var framewidth=parseInt(jQuery('#dialog').css('width'))-40;
		jQuery(id).html("<table border='0'cellpadding='0'cellspacing='0'width='100%'class='caseHeader'><tr><td>&nbsp;</td><td valign='top'class='close'><a href='javascript:void(0);' class='close'>close</a></td></tr>"+
			'<tr><td><iframe src="'+el.href+'" width="'+framewidth+'" height="'+frameheight+'" frameborder="0" scrolling="no" id="iframe_map"></iframe></td>'+
			"<td><div class='scrolls'><a href='javascript:void(0);' id='scrollUpd'><img src='"+theme_url+"/images/arrow_up.gif'></a><br /><a href='javascript:void(0);' id='scrollDownd'><img src='"+theme_url+"/images/arrow_down.gif'></a></div>"+
			'</td></tr></table>'
			);
		jQuery('.close').click(function (e) {
				e.preventDefault();
				jQuery('#lightbox-overlay').hide();
				jQuery('.window').hide();
				jQuery('#dialog').css({'width':716});
		});
		var pos=0;
		var k=5;
		var st=null;
		var h1=frameheight;
		jQuery("#scrollUpd").mousedown(function(){
			if(pos+k>0)return;
			k=Math.abs(k);
			st=setInterval(movePosit,10);
		});
		jQuery("#scrollUpd").mouseup(function(){
			clearInterval(st);
		});
		jQuery("#scrollUpd").mouseout(function(){
			clearInterval(st);
		});
		jQuery("#scrollDownd").mouseout(function(){
			clearInterval(st);
		});
		jQuery("#scrollDownd").mouseup(function(){
			clearInterval(st);
		});

		jQuery("#scrollDownd").mousedown(function(){
			//if(h1-h2>pos+50)return;
			k=-Math.abs(k);
			st=setInterval(movePosit,10);
			});
		function movePosit(){
			pos+=k;
			/*if(pos+k>0||(h1-h2>pos+50&&k<0))
			{
				clearInterval(st);
				return;
			}*/
			window.frames[0].scrollBy(0,-k);
		}
		
}