/*
Triumfglass.se/Press
*/

$(document).ready(function() {

/* Cinema slideshow
********************************************* */
if( $( '#cinema' ).length > 0 ) {		

	// Load Cycle plugin for
	// slideshow to work
	
	if( $( '#cinema.front-page' ).length > 0 ) {	
		$('#cinema.front-page').cycle({
  			slideExpr: 'div>div.slide',
			fx:			'fade',
			speed:  	450,
			timeout: 	6000,
			next:   	'#cinema-nav-next', 
			prev:   	'#cinema-nav-prev'
		});
	} else {
		$('#cinema').cycle({ 
			slideExpr: 'div>img:first-child',
			fx:			'fade',
			speed:  	450,
			timeout: 	0,
			next:   	'#cinema-nav-next', 
			prev:   	'#cinema-nav-prev',
			pager:		'ul#cinema-pager',
			pagerAnchorBuilder: cinemaPagination
		});	
	}

}

/* Cinema slideshow
********************************************* */
if( $( 'ul#product-list' ).length > 0 ) {		
	$( 'ul#product-list li' ).hover(
	  function () {
		$( 'a > img', this ).stop().animate({
			top: '-5px'
		}, 200 );
	  },
	  function () {
		$( 'a > img', this ).stop().animate({
			top: '0'
		}, 200 );
	  }
	);
}

/* Voting functionality
********************************************* */

if( $( '#voting-form' ).length > 0 ) {
	$( '#voting-form' ).submit(function() {
		if( ! $( '#voting-form ul.rating li.whole' ).length > 0 ) {
			alert( 'Du har inte betygsatt glassen.' );
			return false;
		}
	});
}
if( $( '#voting-result' ).length > 0 ) {
	$( '#voting-result .close' ).click(function() {
		$( '#voting-result' ).fadeOut( 300 );
	});
}
/* Expandable h2
********************************************* */

if( $( 'h2.expandable' ).length > 0 ) {
	$( 'h2.expandable' ).click(function() {
		
		if( ! $( this ).hasClass( 'active' ) ) {
			$( '+ div', this ).slideDown( 600 );
			$( this ).addClass( 'active' );
		} else {
			$( '+ div', this ).slideUp( 600 );
			$( this ).removeClass( 'active' );
		}
		
	});
}

/* CPT listing functions
********************************************* */
	
if( $( 'ul#cpt-cat-navigation' ).length > 0 ) {
	
	// Category Menu - onclick event
	$( 'ul#cpt-cat-navigation a' ).click( function(){
		activateCategory( $( this ).attr( 'href' ) );
	});
	
	// Set first category in navigation as active
	activateCategory( $( 'ul#cpt-cat-navigation li:first-child a' ).attr( 'href' ) );

}

});

function activateCategory( ci ) {
	
	// Remove currently active on navigation
	// menu and titles. Hide meanwhile.
	$( '.cpt-title, ul.cpt-list' ).hide();
	$( 'ul#cpt-cat-navigation a, .cpt-title' ).removeClass( 'active' );
	
	// Set active menu alternative
	// and set active title
	$( 'ul#cpt-cat-navigation a[href="' + ci + '"]' ).addClass( 'active' );
	$( ci + '.cpt-title, ' + ci + '.cpt-title + ul.cpt-list' ).fadeIn( 200 );
	
}
function cinemaPagination(idx, slide) {
	return '<li><a href="#"><span></span><img src="'+$( slide ).next( 'img' ).attr( 'src' )+'" alt="" /></a></li>';
}
function NewWindow(mypage,myname,w,h,scroll,pos){ if(pos=="random"){LeftPosition=(screen.width)?Math.floor(Math.random()*(screen.width-w)):100;TopPosition=(screen.height)?Math.floor(Math.random()*((screen.height-h)-75)):100;} if(pos=="center"){LeftPosition=(screen.width)?(screen.width-w)/2:100;TopPosition=(screen.height)?(screen.height-h)/2:100;} else if((pos!="center" && pos!="random") || pos==null){LeftPosition=0;TopPosition=20} settings='width='+w+',height='+h+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no'; win=window.open(mypage,myname,settings);}
/*
	//On Click Event
	jQuery("ul#tabs li").click(function() {
		jQuery("ul#tabs li").removeClass("active"); //Remove any "active" class
		jQuery(this).addClass("active"); //Add "active" class to selected tab
		jQuery(".tab_content").hide(); //Hide all tab content

		var activeTab = jQuery(this).find("a").attr("href"); //Find the href attribute value to identify the active tab + content
		jQuery(activeTab).fadeIn(); //Fade in the active ID content
		return false;
	});
*/
