
var cc = new CookieHandler();

$(function(){
		
	$(".nav li ul").hide();

	$(".nav li").bind("mouseover", function(){$(this).find("ul").show();});
	$(".nav li").bind("mouseout", function(){$(this).find("ul").hide();});
	
	$('#image').cycle({ 
		fx:    'fade', 
		speed:  2500 
	 });

});	

function playVideo(id){
	var videoArr = new Array();
	$.post("include/loadVideo.php", { id: id },   
	function(video) {	
		videoArr = explode("<>", video);
		cc.setCookie('videoLoad', videoArr[5], 3600);
		cc.setCookie('videoCopy', videoArr[3], 3600);
		window.location = 'Videos';	
	});
}

function explode (delimiter, string, limit) {
    var emptyArray = {
        0: ''
    };
    if (arguments.length < 2 || typeof arguments[0] == 'undefined' || typeof arguments[1] == 'undefined') {
        return null;
    }

    if (delimiter === '' || delimiter === false || delimiter === null) {
        return false;
    }

    if (typeof delimiter == 'function' || typeof delimiter == 'object' || typeof string == 'function' || typeof string == 'object') {
        return emptyArray;
    }

    if (delimiter === true) {
        delimiter = '1';
    }

    if (!limit) {
        return string.toString().split(delimiter.toString());
    } else {
        var splitted = string.toString().split(delimiter.toString());
        var partA = splitted.splice(0, limit - 1);
        var partB = splitted.join(delimiter.toString());
        partA.push(partB);
        return partA;
    }
}

function showall(ln){
	for(i=0; i < ln; i++){
		//ga(i);
		$("#a"+i).show();
		$(".faqArrow"+i).hide();
	}
}

function popWin(theURL,winName,features) {
  window.open(theURL,winName,features);
}
function mailing_list(div_id, in1){
	
	data1 = $('#'+in1).val();
	
	AtPos = data1.indexOf("@")
	StopPos = data1.lastIndexOf(".")
	
	if (AtPos == -1 || StopPos == -1) {
		alert("Not a valid email address");
		return;
	}else if (StopPos < AtPos) {
		alert("Not a valid email address");
		return;
	}else if (StopPos - AtPos == 1) {
		alert("Not a valid email address");
		return;
	}
	if(data1 == "" || data1 == "your email"){
		return;
	}
	$('.sbtn').html('<img src="images/sgloading.gif">');
	$.post("include/subscribe.php", { email: data1 },
		function(data) {
		$('#singup_box').hide();	
		$('#thumbText').html(data);
	});
}

function playVideoHome(){
	cc.setCookie('videoLoadHome', 'home', 3600);
	window.location = 'Videos';	
}

var qq;
function qa(id){					 
	if ($('#a'+id).is(':hidden') ) {
		$("#a"+id).show();
		$(".faqArrow"+id).hide();
		if(qq){
			$("#a"+qq).hide();
			$(".faqArrow"+qq).show();
		}
		qq = id;
	}else{
		$("#a"+id).hide();
		$(".faqArrow"+id).show();
		qq = undefined;
	}	
}



function CookieHandler() {

	this.setCookie = function (name, value, seconds) {
 
		if (typeof(seconds) != 'undefined') {
			var date = new Date();
			date.setTime(date.getTime() + (seconds*1000));
			var expires = "; expires=" + date.toGMTString();
		}
		else {
			var expires = "";
		}
 
		document.cookie = name+"="+value+expires+"; path=/";
		
	}
 
	this.getCookie = function (name) {
 
		name = name + "=";
		var carray = document.cookie.split(';');
 
		for(var i=0;i < carray.length;i++) {
			var c = carray[i];
			while (c.charAt(0)==' ') c = c.substring(1,c.length);
			if (c.indexOf(name) == 0) return c.substring(name.length,c.length);
		}
 
		return null;
	}
 
	this.deleteCookie = function (name) {
		this.setCookie(name, "", -1);
	}
 
}

