/***********************************************************************************************************************
DOCUMENT: includes/javascript.js
DEVELOPED BY: Ryan Stemkoski
COMPANY: Zipline Interactive
EMAIL: ryan@gozipline.com
PHONE: 509-321-2849
DATE: 3/26/2009
UPDATED: 3/25/2010
DESCRIPTION: This is the JavaScript required to create the accordion style menu.  Requires jQuery library
NOTE: Because of a bug in jQuery with IE8 we had to add an IE stylesheet hack to get the system to work in all browsers. I hate hacks but had no choice :(.
************************************************************************************************************************/
$(document).ready(function() {
	 
	//ACCORDION BUTTON ACTION (ON CLICK DO THE FOLLOWING)
	$('.accordionButton').click(function() {

		//REMOVE THE ON CLASS FROM ALL BUTTONS
		$('.accordionButton').removeClass('on');
		  
		//NO MATTER WHAT WE CLOSE ALL OPEN SLIDES
	 	$('.accordionContent').slideUp('normal');
   
		//IF THE NEXT SLIDE WASN'T OPEN THEN OPEN IT
		if($(this).next().is(':hidden') == true) {
			
			//ADD THE ON CLASS TO THE BUTTON
			$(this).addClass('on');
			  
			//OPEN THE SLIDE
			$(this).next().slideDown('normal');
		 } 
		  
	 });
	  
	
	/*** REMOVE IF MOUSEOVER IS NOT REQUIRED ***/
	
	//ADDS THE .OVER CLASS FROM THE STYLESHEET ON MOUSEOVER 
	$('.accordionButton').mouseover(function() {
		$(this).addClass('over');
		
	//ON MOUSEOUT REMOVE THE OVER CLASS
	}).mouseout(function() {
		$(this).removeClass('over');										
	});
	
	/*** END REMOVE IF MOUSEOVER IS NOT REQUIRED ***/
	
	$("#open").trigger('click');
	/********************************************************************************************************************
	CLOSES ALL S ON PAGE LOAD
	********************************************************************************************************************/	
	$('.accordionContent').hide();

	/* HAMISHs CODE FOR STYLE FOR CONTACT AND NEWSLETTER */

	$('.acc_item_large_header').mouseover(function() {
		$(this).addClass('acc_item_large_header_hover');
		$('.acc_item_large_body').addClass('acc_item_large_body_hover');
	//ON MOUSEOUT REMOVE THE OVER CLASS
	}).mouseout(function() {
		$(this).removeClass('acc_item_large_header_hover');		
		$('.acc_item_large_body').removeClass('acc_item_large_body_hover');
	});
	
	$('.acc_item_large_body').mouseover(function() {
		$(this).addClass('acc_item_large_body_hover');
		$('.acc_item_large_header').addClass('acc_item_large_header_hover');
	}).mouseout(function() {
		$(this).removeClass('acc_item_large_body_hover');		
		$('.acc_item_large_header').removeClass('acc_item_large_header_hover');
	});

	$('.acc_item_large_headerprop1').mouseover(function() {
		$(this).addClass('acc_item_large_headerprop_hover1');
		$('.acc_item_large_bodyprop1').addClass('acc_item_large_bodyprop_hover1');
	//ON MOUSEOUT REMOVE THE OVER CLASS
	}).mouseout(function() {
		$(this).removeClass('acc_item_large_headerprop_hover1');		
		$('.acc_item_large_bodyprop1').removeClass('acc_item_large_bodyprop_hover1');
	});
	
	$('.acc_item_large_bodyprop1').mouseover(function() {
		$(this).addClass('acc_item_large_bodyprop_hover1');
		$('.acc_item_large_headerprop1').addClass('acc_item_large_headerprop_hover1');
	}).mouseout(function() {
		$(this).removeClass('acc_item_large_bodyprop_hover1');		
		$('.acc_item_large_headerprop1').removeClass('acc_item_large_headerprop_hover1');
	});

	$('.acc_item_large_headerprop2').mouseover(function() {
		$(this).addClass('acc_item_large_headerprop_hover2');
		$('.acc_item_large_bodyprop2').addClass('acc_item_large_bodyprop_hover2');
	//ON MOUSEOUT REMOVE THE OVER CLASS
	}).mouseout(function() {
		$(this).removeClass('acc_item_large_headerprop_hover2');		
		$('.acc_item_large_bodyprop2').removeClass('acc_item_large_bodyprop_hover2');
	});
	
	$('.acc_item_large_bodyprop2').mouseover(function() {
		$(this).addClass('acc_item_large_bodyprop_hover2');
		$('.acc_item_large_headerprop2').addClass('acc_item_large_headerprop_hover2');
	}).mouseout(function() {
		$(this).removeClass('acc_item_large_bodyprop_hover2');		
		$('.acc_item_large_headerprop2').removeClass('acc_item_large_headerprop_hover2');
	});

	$('.acc_item_large_headerprop3').mouseover(function() {
		$(this).addClass('acc_item_large_headerprop_hover3');
		$('.acc_item_large_bodyprop3').addClass('acc_item_large_bodyprop_hover3');
	//ON MOUSEOUT REMOVE THE OVER CLASS
	}).mouseout(function() {
		$(this).removeClass('acc_item_large_headerprop_hover3');		
		$('.acc_item_large_bodyprop3').removeClass('acc_item_large_bodyprop_hover3');
	});
	
	$('.acc_item_large_bodyprop3').mouseover(function() {
		$(this).addClass('acc_item_large_bodyprop_hover3');
		$('.acc_item_large_headerprop3').addClass('acc_item_large_headerprop_hover3');
	}).mouseout(function() {
		$(this).removeClass('acc_item_large_bodyprop_hover3');		
		$('.acc_item_large_headerprop3').removeClass('acc_item_large_headerprop_hover3');
	});
	
	var href_goto_url = "";

  $("#busdetail-content a").click(function () { 
		
		var href = this.href;
		href_goto_url = this.href;
		if(/\.(pdf)|(pdf)$/.test(href)){
			var cid = (getUrlVars()["id"]);
			
			$("#counterchk").load("http://www.ascend.com.au/includes/counter.php",{atask: "showpdf", prop_id: cid}, function(html){
				;
			});
			$('#pdfdialog').dialog('open');
			return false;
		}
		else
			return true; 
	});   

	$('#pdfdialog').dialog({
		autoOpen: false,
		width: 600,
		buttons: {
			"I Agree": function() { 
				var cid2 = (getUrlVars()["id"]);
				$("#counterchk").load("http://www.ascend.com.au/includes/counter.php",{atask: "pdf", prop_id: cid2}, function(html){
					;
				});
				$(this).dialog("close"); 

				window.open(href_goto_url);
			}, 
			"Cancel": function() { 
				$(this).dialog("close"); 
			} 
		}
	});
	
});


function getUrlVars()
{
    var vars = [], hash;
    var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
    for(var i = 0; i < hashes.length; i++)
    {
        hash = hashes[i].split('=');
        vars.push(hash[0]);
        vars[hash[0]] = hash[1];
    }
    return vars;
}

function logPropertyHit()
{
	var cid2 = (getUrlVars()["id"]);
	
	if(!isNaN(cid2))
	{
		$("#logprophit").load("http://www.ascend.com.au/includes/counter.php",{atask: "propview", prop_id: cid2}, function(html){
			;
		});
	}
}
