$(window).load(function(){
	initDropDown();
	initSkypePluginDisable();
	//initPrettyPhoto();
});



$(function(){
	initZoomGallery();
	initParallaxGallery();
	initSelectedClass();
	initAccordion();
	pageImage();
});


function pageImage() {
	$('.promo-nav .tab').hide().eq($('.promo-nav li').filter('.selected').index()).show();
	/*
	items.each( function (i){
		if ($(thixqas).hasClass('selected')) tabs.hide().eq(i).show();
	});
	*/
}
function initAccordion(){
	jQuery(document).ready(function() {
  		jQuery(".expandContent").hide();
  		//toggle the componenet
  		jQuery(".expandHeader").click(function()
 		 {
    	jQuery(this).next(".expandContent").slideToggle(500);
 		});
		});
};

function initPrettyPhoto(){
	$("a[rel^='videoShow']").prettyPhoto();
};

function initSkypePluginDisable(){
	window.setTimeout(function() {
		$('.skype_pnh_container').html('');
		$('.skype_pnh_print_container').removeClass('skype_pnh_print_container');
	}, 800);
};

function initSelectedClass(){
	var windowUrl = window.location.href;
	$('#main-menu > ul li').each(function(){
		var holder = $(this);
		var link = holder.find('>a');
		var href = link.attr('href'); 
		var index = windowUrl.indexOf(href);
		if (index != -1) {
			if (windowUrl.charAt(index+href.length) == '/' || windowUrl.charAt(index+href.length) == '') {
				holder.addClass('selected');
				holder.parents('li').addClass('selected');
			}
		}
	});
}

function initParallaxGallery(){
	var holder = $('div.gallery');
	var galleryNav = $('div.gallery-nav-holder');
	if (!holder.length) return;
	
	//options
	var autoplay = true;
	var switchTime = 10000;
	
	var upBtn = $('a.btn-left',galleryNav);
	var downBtn = $('a.btn-right',galleryNav);
	var layers = $('div.sliders-holder,div.layer,div.images-holder',holder).not('.water-mark');
	var images = $('div.image',layers)
	var slides = $('div.slide',layers);
	var switcherHolder = $('div.gallery-nav',galleryNav);
	var holderH = holder.height();
	var imagesH = images.eq(0).height();
	var current = 0;
	var duration = 1250;
	var easing = 'easeInOutCirc';
	var switcher;
	var timer;
	
	createPaging();
	bindEvents();
	refreshStatus();
	startPlay();
	
	function bindEvents(){
		downBtn.click(nextSlide);
		upBtn.click(prevSlide);
		switcher.each(function(i){
			var link = $(this);
			link.click(function(){
				showSlide(i);
				return false;
			});
		});
		if (autoplay) $('#header').bind({
			mouseenter:function(){
				autoplay = false;
				clearTimeout(timer);
			},
			mouseleave:function(){
				autoplay = true;
				startPlay();
			}
		})
		
	}

	function createPaging(){
		var list = $('<ul></ul>');
		slides.each(function(i){
			var slide = $(this);
			var li = $('<li><a href="#">'+(i+1)+'</a></li>');
			li.appendTo(list);
		});
		list.appendTo(switcherHolder);
		switcher = $('li',switcherHolder);
	}
	
	function nextSlide(){
		current++;
		if (current > slides.length-1) current = 0;
		move();
		return false;
	}
	
	function prevSlide(){
		current--;
		if (current < 0) current = slides.length-1;
		move();
		return false;
	}
	
	function showSlide(i){
		if (current == i) return;
		current = i;
		move();
	}
	
	function move(){
		var flag = false;
		clearTimeout(timer);
		layers.each(function(i){
			var layer = $(this);
			var step;
			if (layer.hasClass('sliders-holder') || layer.hasClass('z-axis-1')) step = holderH
			else if (layer.hasClass('images-holder')) step = imagesH
			else {
				step = (i+1)/10*holderH;
			}
			layer.stop().animate({top:-current*step},{duration:duration,easing:easing,complete:function(){
				if (!flag) {
					flag = true;
					startPlay();
				}
			}});
		});
		refreshStatus();
	}
	
	function refreshStatus(){
		switcher.removeClass('active');
		switcher.eq(current).addClass('active');
	}
	
	function startPlay(){
		if (autoplay) {
			clearTimeout(timer);
			timer = setTimeout(function(){
				nextSlide();
			},switchTime);
		}
	}
}

function initZoomGallery(){
	var mainHolder = $('div.circle-gallery');
	if (!mainHolder.length) return;
	var smallFlag;
	mainHolder.hasClass('small-circle-gallery') ? smallFlag = true : smallFlag = false;
	var IE = $.browser.msie;
	var holder = $('>div.gall-holder',mainHolder);
	var slider = $('>ul',holder);
	var slides = $('>li',slider);
	var circles = $('>div',slides);
	var activeDiv = $('img.active-bg',slides);
	var noActiveDiv = $('img.bg',slides).not('.active-bg');
	var infoText = $('div.info-text',slides);
	var btns = $('div.btn',slides);
	var headings = $('div.c-header',slides);
	var nextBtn = $('a.btn-right',mainHolder);
	var prevBtn = $('a.btn-left',mainHolder);
	
	var headingTop = '50%';
	if (smallFlag) headingTop = '35%'
	var marginTop = 18;
	if (smallFlag) marginTop = 11;
	
	var slideW = slides.eq(0).width();
	var step = slides.eq(0).outerWidth(true);
	var circleW = circles.eq(0).width();
	var duration = 800;
	if ($.browser.version < 9 && IE)  duration = 1200;
	var offset = 0;
	var holderW = holder.width();
	var visibleSlides = Math.floor(holderW/slideW);
	var diff = Math.floor(visibleSlides /2);
	var previous = -1;
	var current = Math.floor(slides.length/2);
	if (smallFlag) {
		current = 0;
		diff = 0;
	}
	var offset = (current-diff)*step;
	setDefaultStyles();
	bindEvents();
	
	function setDefaultStyles(){
		if (slideW*slides.length <= holderW && smallFlag) {
			nextBtn.add(prevBtn).hide();
			slider.css({marginLeft:holderW/2-slideW*slides.length/2});
		} else {
			slider.css({marginLeft:-offset});
		} 

		if (!IE) activeDiv.css({display:'none',opacity:0});
		
		if (smallFlag) return;
		circles.eq(current).animate({width:slideW,height:slideW,marginTop:0});
		if (!IE) activeDiv.eq(current).css({opacity:1,display:'block'})
		else activeDiv.eq(current).css({display:'block'});
		headings.eq(current).css({top:'25%'});
		noActiveDiv.eq(current).hide();
	}
	
	function bindEvents(){
		nextBtn.click(nextSlide);
		prevBtn.click(prevSlide);
		slides.each(function(i){
			var slide = $(this);
		
			if (smallFlag) {
				slide.mouseenter(function(){
					increaseSize(i,function(){
						showText(i);
					});
				}).mouseleave(function(){
					decreaseSize(i);
					hideText(i);
				});
			} else {
				slide.mouseenter(function(){
					if (i == current) showText(i);
				}).mouseleave(function(){
					if (i == current) hideText(i);
				});
			}
			slide.click(function(){
				if (i == current || smallFlag) {
					window.location.href = $(this).find('div.btn a').attr('href');
				} else if (!smallFlag) {
					showSlide(i);
				}
			});
		});
	}
	
	function nextSlide(){
		if (current >= slides.length -1) return false;
		if (smallFlag && current >= slides.length-visibleSlides) return false;
		previous = current;
		current++;
		move();
		return false;
	}
	
	function prevSlide(){
		if (current == 0) return false;
		previous = current;
		current--;
		move();
		return false;
	}
	
	function showSlide(i){
		if (i== current) return;
		previous = current;
		current = i;
		move();
	}
	
	function move(){
		offset = (current-diff)*step;
		if ($.browser.version < 9 && IE) {
			slider.stop().animate({marginLeft:-offset},180,function(){
				if (smallFlag) return;  	
				increaseSize(current);
				decreaseSize(previous);
			});
		} else {
		slider.stop().animate({marginLeft:-offset},duration);
		if (smallFlag) return;
		increaseSize(current);
		decreaseSize(previous);
		}
	}

	
	function increaseSize(i,cb){
		circles.eq(i).stop().animate({
			width:slideW,
			height:slideW,
			marginTop:0
		},duration);
		if (!IE) {
			activeDiv.eq(i).stop().css({display:'block'}).animate({opacity:1},duration,function(){
				if (typeof cb === 'function') cb();
				noActiveDiv.eq(i).hide();
			});
		} else {
			activeDiv.eq(i).css({display:'block'});
			noActiveDiv.eq(i).hide();
			if (typeof cb === 'function') cb();
		}
		headings.eq(i).stop().animate({top:'16%'},duration);
	}
	
	function decreaseSize(i){
		circles.eq(i).stop().animate({
			width:circleW,
			height:circleW,
			marginTop:marginTop
		},duration);
		noActiveDiv.eq(i).show();
		if (!IE) {
			activeDiv.eq(i).stop().animate({opacity:0},duration,function(){
				$(this).css({display:'none'});
			});
		} else {
			activeDiv.eq(i).css({display:'none'});
		}
		headings.eq(i).stop().animate({top:headingTop},duration);
	}
	
	function showText(i){
		infoText.eq(i).stop().css({top:'100%',display:'block'}).animate({top:'50%'},duration,function(){
			btns.eq(i).fadeIn(duration);
		});
	}
	//headings
	function hideText(i){
		infoText.eq(i).stop().animate({top:'100%'},duration,function(){
			$(this).css({display:'none'});
		});
		btns.eq(i).fadeOut(duration);
	}
}

function initGallery(){
	$('#header').slideshow();
}

function initDropDown(){
	var duration = 500;
	$('#main-menu > ul > li').each(function(){
		var holder = $(this);
		var dropHolder = $('div.drop-holder',holder);
		if (!dropHolder.length) return;
		var drop = $('div.drop',dropHolder);
		dropHolder.css({width:holder.width()});
		holder.mouseenter(show).mouseleave(hide)
		
		function show(){
			if (holder.hasClass('hover')) {
				drop.stop().animate({marginTop:0},duration);
			} else {
				holder.addClass('hover');
				drop.css({
					marginTop:-drop.height()
				}).animate({marginTop:0},duration);
			}
		}
		
		function hide(){
			drop.stop().animate({marginTop:-drop.height()},duration,function(){
				holder.removeClass('hover');
			});
		}
	});
}

function initCircleGallery(){
	new circleGallery($('div.circle-gallery'));
}

function circleGallery(el,options){
	this.init(el,options);
}

circleGallery.prototype = {
	init:function(el,options){
		var obj = this;
		this.options = $.extend({
			btnPrev:'a.btn-right',
			btnNext:'a.btn-left',
			holder:'>div',
			slider:'>ul',
			slides:'>li',
			duration:550,
			easing:'swing'
		},options);
		
		this.mainHolder = el;
		this.btnNext = $(this.options.btnNext,this.mainHolder);
		this.btnPrev = $(this.options.btnPrev,this.mainHolder);
		this.holder = $(this.options.holder,this.mainHolder);
		this.slider = $(this.options.slider,this.holder);
		this.slides = $(this.options.slides,this.slider);
		this.slides.each(function(i){
			$(this).attr({rel:i});
		});
		this.slideW = this.slides.eq(0).outerWidth(true);
		this.startMargin = this.slideW*this.slides.length;
		this.slider.append(this.slides.clone()).prepend(this.slides.clone()).css({marginLeft:-this.startMargin});
		this.holderW = this.holder.width();
		this.visibleSlides = Math.floor(this.holderW/this.slideW);
		this.diff = Math.floor(this.visibleSlides /2);
		this.current = this.slides.length;
		this.newSlides = $(this.options.slides,this.slider);
		this.animation = false;
		this.refreshStatus();
		
		this.btnPrev.click(function(){
			obj.prevSlide();
			return false;
		});
		this.btnNext.click(function(){
			obj.nextSlide();
			return false;
		});
		
		this.newSlides.each(function(i){
			var slide = $(this);
			slide.click(function(){
				obj.showSlide(i-obj.diff);
			});
		});
	},
	showSlide:function(slideInd){
		if (this.current == slideInd || this.animation) return;
		this.current = slideInd;
		this.switchSlide();
	},
	nextSlide:function(){
		if (this.animation) return;
		this.current++;
		this.switchSlide();
	},
	prevSlide:function(){
		if (this.animation) return;
		this.current--;
		this.switchSlide();
	},
	switchSlide:function(){
		var obj = this;
		this.newSlides.removeClass('active');
		this.offset = this.current*this.slideW;
		this.animation = true;
		this.slider.animate({marginLeft:-this.offset},{
			duration:this.options.duration,
			easing:this.options.easing,
			complete:function(){
				if (obj.current > obj.slides.length*2) {
					obj.current -= obj.slides.length;
					obj.slider.css({marginLeft:-(obj.offset-obj.startMargin)});
				} else if (obj.current <= obj.slides.length) {
					obj.current += obj.slides.length;
					obj.slider.css({marginLeft:-(obj.offset+obj.startMargin)});
				}
				obj.refreshStatus();
				obj.animation = false;
			}
		});
	},
	refreshStatus:function(){
		var tmp = parseInt(this.newSlides.eq(this.current).attr('rel'))+this.diff;
		if (tmp >= this.slides.length) tmp -= this.slides.length
		this.newSlides.filter('[rel='+tmp+']').addClass('active');
	}
}

/*
 * jQuery Easing v1.3 - http://gsgd.co.uk/sandbox/jquery/easing/
 *
 * Uses the built in easing capabilities added In jQuery 1.1
 * to offer multiple easing options
 *
 * TERMS OF USE - jQuery Easing
 * 
 * Open source under the BSD License. 
 * 
 * Copyright В© 2008 George McGinley Smith
 * All rights reserved.
 * 
 * Redistribution and use in source and binary forms, with or without modification, 
 * are permitted provided that the following conditions are met:
 * 
 * Redistributions of source code must retain the above copyright notice, this list of 
 * conditions and the following disclaimer.
 * Redistributions in binary form must reproduce the above copyright notice, this list 
 * of conditions and the following disclaimer in the documentation and/or other materials 
 * provided with the distribution.
 * 
 * Neither the name of the author nor the names of contributors may be used to endorse 
 * or promote products derived from this software without specific prior written permission.
 * 
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
 *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 *  EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
 *  GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 
 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
 *  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 
 * OF THE POSSIBILITY OF SUCH DAMAGE. 
 *
*/

// t: current time, b: begInnIng value, c: change In value, d: duration
jQuery.easing['jswing'] = jQuery.easing['swing'];

jQuery.extend( jQuery.easing,
{
	def: 'easeOutQuad',
	swing: function (x, t, b, c, d) {
		//alert(jQuery.easing.default);
		return jQuery.easing[jQuery.easing.def](x, t, b, c, d);
	},
	easeInQuad: function (x, t, b, c, d) {
		return c*(t/=d)*t + b;
	},
	easeOutQuad: function (x, t, b, c, d) {
		return -c *(t/=d)*(t-2) + b;
	},
	easeInOutQuad: function (x, t, b, c, d) {
		if ((t/=d/2) < 1) return c/2*t*t + b;
		return -c/2 * ((--t)*(t-2) - 1) + b;
	},
	easeInCubic: function (x, t, b, c, d) {
		return c*(t/=d)*t*t + b;
	},
	easeOutCubic: function (x, t, b, c, d) {
		return c*((t=t/d-1)*t*t + 1) + b;
	},
	easeInOutCubic: function (x, t, b, c, d) {
		if ((t/=d/2) < 1) return c/2*t*t*t + b;
		return c/2*((t-=2)*t*t + 2) + b;
	},
	easeInQuart: function (x, t, b, c, d) {
		return c*(t/=d)*t*t*t + b;
	},
	easeOutQuart: function (x, t, b, c, d) {
		return -c * ((t=t/d-1)*t*t*t - 1) + b;
	},
	easeInOutQuart: function (x, t, b, c, d) {
		if ((t/=d/2) < 1) return c/2*t*t*t*t + b;
		return -c/2 * ((t-=2)*t*t*t - 2) + b;
	},
	easeInQuint: function (x, t, b, c, d) {
		return c*(t/=d)*t*t*t*t + b;
	},
	easeOutQuint: function (x, t, b, c, d) {
		return c*((t=t/d-1)*t*t*t*t + 1) + b;
	},
	easeInOutQuint: function (x, t, b, c, d) {
		if ((t/=d/2) < 1) return c/2*t*t*t*t*t + b;
		return c/2*((t-=2)*t*t*t*t + 2) + b;
	},
	easeInSine: function (x, t, b, c, d) {
		return -c * Math.cos(t/d * (Math.PI/2)) + c + b;
	},
	easeOutSine: function (x, t, b, c, d) {
		return c * Math.sin(t/d * (Math.PI/2)) + b;
	},
	easeInOutSine: function (x, t, b, c, d) {
		return -c/2 * (Math.cos(Math.PI*t/d) - 1) + b;
	},
	easeInExpo: function (x, t, b, c, d) {
		return (t==0) ? b : c * Math.pow(2, 10 * (t/d - 1)) + b;
	},
	easeOutExpo: function (x, t, b, c, d) {
		return (t==d) ? b+c : c * (-Math.pow(2, -10 * t/d) + 1) + b;
	},
	easeInOutExpo: function (x, t, b, c, d) {
		if (t==0) return b;
		if (t==d) return b+c;
		if ((t/=d/2) < 1) return c/2 * Math.pow(2, 10 * (t - 1)) + b;
		return c/2 * (-Math.pow(2, -10 * --t) + 2) + b;
	},
	easeInCirc: function (x, t, b, c, d) {
		return -c * (Math.sqrt(1 - (t/=d)*t) - 1) + b;
	},
	easeOutCirc: function (x, t, b, c, d) {
		return c * Math.sqrt(1 - (t=t/d-1)*t) + b;
	},
	easeInOutCirc: function (x, t, b, c, d) {
		if ((t/=d/2) < 1) return -c/2 * (Math.sqrt(1 - t*t) - 1) + b;
		return c/2 * (Math.sqrt(1 - (t-=2)*t) + 1) + b;
	},
	easeInElastic: function (x, t, b, c, d) {
		var s=1.70158;var p=0;var a=c;
		if (t==0) return b;  if ((t/=d)==1) return b+c;  if (!p) p=d*.3;
		if (a < Math.abs(c)) { a=c; var s=p/4; }
		else var s = p/(2*Math.PI) * Math.asin (c/a);
		return -(a*Math.pow(2,10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )) + b;
	},
	easeOutElastic: function (x, t, b, c, d) {
		var s=1.70158;var p=0;var a=c;
		if (t==0) return b;  if ((t/=d)==1) return b+c;  if (!p) p=d*.3;
		if (a < Math.abs(c)) { a=c; var s=p/4; }
		else var s = p/(2*Math.PI) * Math.asin (c/a);
		return a*Math.pow(2,-10*t) * Math.sin( (t*d-s)*(2*Math.PI)/p ) + c + b;
	},
	easeInOutElastic: function (x, t, b, c, d) {
		var s=1.70158;var p=0;var a=c;
		if (t==0) return b;  if ((t/=d/2)==2) return b+c;  if (!p) p=d*(.3*1.5);
		if (a < Math.abs(c)) { a=c; var s=p/4; }
		else var s = p/(2*Math.PI) * Math.asin (c/a);
		if (t < 1) return -.5*(a*Math.pow(2,10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )) + b;
		return a*Math.pow(2,-10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )*.5 + c + b;
	},
	easeInBack: function (x, t, b, c, d, s) {
		if (s == undefined) s = 1.70158;
		return c*(t/=d)*t*((s+1)*t - s) + b;
	},
	easeOutBack: function (x, t, b, c, d, s) {
		if (s == undefined) s = 1.70158;
		return c*((t=t/d-1)*t*((s+1)*t + s) + 1) + b;
	},
	easeInOutBack: function (x, t, b, c, d, s) {
		if (s == undefined) s = 1.70158; 
		if ((t/=d/2) < 1) return c/2*(t*t*(((s*=(1.525))+1)*t - s)) + b;
		return c/2*((t-=2)*t*(((s*=(1.525))+1)*t + s) + 2) + b;
	},
	easeInBounce: function (x, t, b, c, d) {
		return c - jQuery.easing.easeOutBounce (x, d-t, 0, c, d) + b;
	},
	easeOutBounce: function (x, t, b, c, d) {
		if ((t/=d) < (1/2.75)) {
			return c*(7.5625*t*t) + b;
		} else if (t < (2/2.75)) {
			return c*(7.5625*(t-=(1.5/2.75))*t + .75) + b;
		} else if (t < (2.5/2.75)) {
			return c*(7.5625*(t-=(2.25/2.75))*t + .9375) + b;
		} else {
			return c*(7.5625*(t-=(2.625/2.75))*t + .984375) + b;
		}
	},
	easeInOutBounce: function (x, t, b, c, d) {
		if (t < d/2) return jQuery.easing.easeInBounce (x, t*2, 0, c, d) * .5 + b;
		return jQuery.easing.easeOutBounce (x, t*2-d, 0, c, d) * .5 + c*.5 + b;
	}
});

/*
 *
 * TERMS OF USE - EASING EQUATIONS
 * 
 * Open source under the BSD License. 
 * 
 * Copyright В© 2001 Robert Penner
 * All rights reserved.
 * 
 * Redistribution and use in source and binary forms, with or without modification, 
 * are permitted provided that the following conditions are met:
 * 
 * Redistributions of source code must retain the above copyright notice, this list of 
 * conditions and the following disclaimer.
 * Redistributions in binary form must reproduce the above copyright notice, this list 
 * of conditions and the following disclaimer in the documentation and/or other materials 
 * provided with the distribution.
 * 
 * Neither the name of the author nor the names of contributors may be used to endorse 
 * or promote products derived from this software without specific prior written permission.
 * 
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
 *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 *  EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
 *  GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 
 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
 *  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 
 * OF THE POSSIBILITY OF SUCH DAMAGE. 
 *
 */
