$j = jQuery.noConflict();

// Loading Plugins
	$j.lazy({ src: '/assets/js/plugins/jquery.cycle.all.min.js', name: 'cycle',cache: true });
	$j.lazy({ src: '/assets/js/plugins/scrollto.js', name: 'scrollto' });
	$j.lazy({ src: '/assets/js/plugins/onload.js', name: 'scrollto' });
	$j.lazy({ src: '/assets/js/plugins/jquery.fancybox-1.3.1.pack.js', name: 'fancybox',cache: true  });
	//$j.lazy({ src: '/assets/js/plugins/ui.tabs.js', name: 'scrollto' });

// End of plugins


function emails() {	
		// Email Converter
	$j('a.email').each(function(){
		e = this.title.replace('/','@');
		this.href=" ";
		this.title="Please Contact Us Via Email";
		this.href = 'mailto:' + e; $j(this).text(e);
	});
}

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 getGiftValues() {


	var gqtr = getUrlVars()["qtr"];
	var productType = getUrlVars()["productType"];
	var productName = getUrlVars()["productName"];
	productName = productName.replace(/\+/g,' ');
	var productPrice = getUrlVars()["productPrice"];
	productPrice = productPrice.slice(0, -3)
	
	$j('#product-name').val(productName);
	$j('#pitem-type').val(productType);
	$j('#product-qtr').val(gqtr);
	$j('#product-price').val(productPrice);
	$j('#total-price').val(productPrice*gqtr);

	if ( productType == "GiftCard" ) {
		$j("#recgiftcard").show();
	}
/*
	if ( productPrice == "GiftCard" ) {
		$j("#recgiftcard").hide();
	} 
*/
	
	$j('#update-qtr').click(function() {
		gqtr = $j('#product-qtr');
		$j('#total-price').delay(200).css("background-color", "#FFFF9C").animate({ backgroundColor: "#FFFFFF"}, 1500);
  		var valn = productPrice;
  		valn = valn*$j('#product-qtr').val();
  		$j('#total-price').val(valn);
  		return false;
	});
}

function getDVDInfo() {

	var gqtr = getUrlVars()["dvd-qtr"];
	var productName = getUrlVars()["productName"];
	productName = productName.replace(/\+/g,' ');
	var productPrice = getUrlVars()["productPrice"];
	productPrice = productPrice.slice(0, -3)
	
	$j('#product-name').val(productName) ;
	$j('#product-qtr').val(gqtr);
	$j('#product-price').val(productPrice);
	
	$j('#total-price').val(productPrice*gqtr);
	$j('#update-qtr').click(function() {
		gqtr = $j('#product-qtr');
		$j('#total-price').delay(200).css("background-color", "#FFFF9C").animate({ backgroundColor: "#FFFFFF"}, 1500);
  		var valn = productPrice;
  		valn = valn*$j('#product-qtr').val();
  		$j('#total-price').val(valn);
  		return false;
	});


}

function openExternal() {
	$j('a[rel*=external]').click( function() { window.open(this.href); return false; });
	$j('a.external').click( function() { window.open(this.href); return false; });
	$j('.external a').click( function() { window.open(this.href); return false; });
}

$j(function() 
{

	emails();

	if ($j('#gift-payment-form').length) { getGiftValues();	}
	if ($j('#dvd-order-form').length) { getDVDInfo(); }
	
	openExternal();

	$j('a#hideDashNotice').click(function() { $j('#dashAnnouncement').slideUp('fast'); return false;});
	
/*	$j("ul.css-tabs").tabs("div.panes > div", {history: true});
	$j('ul.css-tabs li a').click(function() {
		return false;
	});
*/
	
	$j('#makeADifference').cycle({ 
	    	fx:'scrollLeft', 
			delay: 80,				// milliseconds = additional delay for first transition (hint: can be negative)
			timeout: 5000,			//  milliseconds between slide transitions (0 to disable auto advance)
			pause: 1,				// boolean = 1 pauses the slideshow on mouseOver
			random: 1,				// boolean = 0 moves through slides sequentially; 1 moves through slides in random order
			speed: 1000,			// number = millisecond transition speed between slides
			fastOnEvent: 1000		// milliseconds = forces fast transitions when triggered manually
	});
		
	$j('#current-projects ul').cycle({ 
		speed: 300,	timeout: 0,	fx:'scrollLeft', next: '#next2', prev: '#prev2', random: 0,  pause: 0
	});
	
	
	$j("a.feature-video").click(function() {
		$j.fancybox({
				'padding'		: 0,
				'autoScale'		: false,
				'transitionIn'	: 'none',
				'transitionOut'	: 'none',
				'title'			: this.title,
				'width'		: 680,
				'height'		: 495,
				'href'			: this.href.replace(new RegExp("watch\\?v=", "i"), 'v/'),
				'type'			: 'swf',
				'swf'			: {
				'wmode'		: 'transparent',
				'allowfullscreen'	: 'true'
				}
			});
	
		return false;
	});

	
	
	if ( $j('div.hero').hasClass("view-hero-True") ) {
		$j('#content_sec .inner').addClass("page-has-banner");
	}
	
	
	$j('div.faq-list div.faq-answer').hide();  
	$j('div.faq-list> a').click(function() {
		$j(this).next('div.faq-answer').slideToggle('fast')
		.siblings('div.faq-answer:visible').slideUp('fast');
	});
	
});


