/**
 * User functions' set
 *
 * initLoad ()
 * clickVideo (ob_li, st_type)
 * clickCategory (ob_li)
 * clickPlaylist (ob_li)
 * clickChannel (ob_li)
 * streamInfo (ob)
 *
 * @version 1.9
 * @author Michal Luberda
 */

//_PRICE_30 = "9.99";
_PRICE_30 = "12.99";

cookie_token = "";
cookie_email = "";

var scroller1  = null;
var scrollbar1 = null;

function scrollbarEvent (o, type) {
	if (type == "mousedown") {
		if (o.className == "Scrollbar-Track") o.style.backgroundColor = "#339451";//track hold color
		else o.style.backgroundColor = "#339451";// slider hold color
	} else {
		if (o.className == "Scrollbar-Track") o.style.backgroundColor = "#ffffff";// track release color
		else o.style.backgroundColor = "#137431";// slider release color
	}
}

function bg_resize() {
	$("#img_bg").width( $(window).width() ).height( $(window).height() ).css( 'top', $(window).scrollTop() + "px" );
	}
 
$(window).resize( function() {
     bg_resize();
     window.setTimeout ("bg_resize()", 250);	
});

$(window).scroll(function() {
    bg_resize();
});

function customlogin () {
    $ ("#li-account a").click ();
}

/**
 * initLoad
 */
 
function initLoad ()
{

    // append menu link
    $ ("#div_menu ul").append ($ ("#div-hidden-pages ul li"));
    $ ("#div_menu ul li").click (function () {
        $ ("#div_menu ul li").removeClass ("li_channel_selected");
        $ (this).addClass ("li_channel_selected");
    });
    
	$( "#div_menu li:gt(0)" ).show();

	if ( $("#li_channel_2537").length == 1 ) {
		$("#welcometext").show();
		}

	// Scrollers
	$("#ul-slides").jcarousel();
	scroller1  = new jsScroller(document.getElementById("div_videos"), 360, 360);
	scrollbar1 = new jsScrollbar (document.getElementById("Scrollbar-Container1"), scroller1, true, scrollbarEvent);

	// Background 100%
	bg_resize();
	
    $ (".ul_channel .li_category:eq(0) .a_video:eq(0)").click ();
	
	/**
	 * contact
	 */
	$ ("#li-contact a").click (function () {
        ob = {
            st_action:    "contact"
        };
        ob_page._post (ob);
        ob_page.id_interval = window.setInterval (
            function () {
                if (ob_page.bo_loaded) {
                    window.clearInterval (ob_page.id_interval);
                    $ ("#div-inner").html (ob_page.ob_output.html);
                    ob_page._preloader (false);
            		scrollbar1.reset ();
            		scrollbar1.reset ();
                }
            }, 100
        );
	});
	
    /**
     * account
     */
    $ ("#li-account a").click (function () {
        $ ("#div_menu ul li").each (function () {
            $ ("#div_menu ul li").removeClass ("li_channel_selected");
        });
        $ (this).parent ("div").parent ("li").addClass ("li_channel_selected");
        ob = {
            st_action:    "cookie",
            st_subaction: "get"
        };
        ob_page._post (ob);
        ob_page.id_interval = window.setInterval (
            function () {
                if (ob_page.bo_loaded) {
                    window.clearInterval (ob_page.id_interval);
                    ar = ob_page.ob_output.html.split (":");
                    
                    // check cookie first
                    if (ar[0] && ar[1]) {
                        
                        cookie_token = ar[0];
                        cookie_email = ar[1];
                        
                        ob = {
                            st_action:    "account",
                            st_subaction: "login",
                            st_email:     cookie_email,
                            st_password:  "",
                            st_token:     cookie_token,
                            ob_parent:    $ ("#div-login")
                        };
                        
                        ob_page._post (ob);
                        ob_page.id_interval = window.setInterval (
                            function () {
                                if (ob_page.bo_loaded) {
                                    window.clearInterval (ob_page.id_interval);
                                    
                                    if (ob_page.ob_output.status) {
                                        // reload account panel on error reseting cookie
                                        ob_page._post ({
                                            st_action:    "cookie",
                                            st_subaction: "reset"
                                        });
                                        ob_page.id_interval = window.setInterval (
                                            function () {
                                                if (ob_page.bo_loaded) {
                                                    window.clearInterval (ob_page.id_interval);
                                                    cookie_email = "";
                                                    cookie_token = "";
                                                    $ ("#li-account a").click ();
                                                }
                                            }, 100
                                        );
                                    }
                                    else {
                                        ob = {
                                            st_action:    "account",
                                            st_subaction: "logout-form",
                                            st_email:     cookie_email,
                                            st_token:     cookie_token
                                        };
                                        ob_page._post (ob);
                                        ob_page.id_interval = window.setInterval (
                                            function () {
                                                if (ob_page.bo_loaded) {
                                                    window.clearInterval (ob_page.id_interval);
                                                    
                                                    $ ("#div-inner").html (ob_page.ob_output.html);
                                                    
                                            		scrollbar1.reset ();
                                            		scrollbar1.reset ();
                                            		
                                                    // logout
                                                    $ ("#inputs-logout").click (function () {
                                                        // reload account panel on error reseting cookie
                                                        ob_page._post ({
                                                            st_action:    "cookie",
                                                            st_subaction: "reset"
                                                        });
                                                        ob_page.id_interval = window.setInterval (
                                                            function () {
                                                                if (ob_page.bo_loaded) {
                                                                    window.clearInterval (ob_page.id_interval);
                                                                    cookie_email = "";
                                                                    cookie_token = "";
                                                                    $ ("#li-account a").click ();
                                                                }
                                                            }, 100
                                                        );
                                                    });
                                                    
                                                    // update
                                                    $ ("#inputs-update").click (function () {
                                                        ob = {
                                                            st_action:    "account",
                                                            st_subaction: "update",
                                                            st_email:     cookie_email,
                                                            st_token:     cookie_token,
                                                            st_firstname: $ ("#input-register-firstname").val (),
                                                            st_lastname:  $ ("#input-register-lastname").val (),
                                                            st_address1:  $ ("#input-register-address1").val (),
                                                            st_address2:  $ ("#input-register-address2").val (),
                                                            st_province:  $ ("#input-register-province").val (),
                                                            st_zip:       $ ("#input-register-zip").val (),
                                                            in_country:   $ ("#select-countries").val (),
                                                            st_password:  $ ("#inputp-register-password").val (),
                                                            st_rpassword: $ ("#inputp-register-rpassword").val (),
                                                            ob_parent:    $ (this)
                                                        };
                                                        ob_page._post (ob);
                                                        ob_page.id_interval = window.setInterval (
                                                            function () {
                                                                if (ob_page.bo_loaded) {
                                                                    window.clearInterval (ob_page.id_interval);
                                                                    
                                                                    $ ("#inputp-register-password").val ("");
                                                                    $ ("#inputp-register-rpassword").val ("");
                                                                    
                                                                    if (ob_page.ob_output.status) {
                                                                        $ ("#h4-status-update").html (ob_page.ob_output.status);
                                                                        $ ("#h4-status-update").attr ("class", (ob_page.ob_output.error ? "error" : "status"));
                                                                        $ ("#h4-status-update").show ();
                                                                    }
                                                                    else {
                                                                        $ ("#h4-status-update").html ("");
                                                                        $ ("#h4-status-update").hide ();
                                                                    }
                                                                    
                                                                    ob_page._preloader (false);
                                                                    
//                                                            		scrollbar1.reset ();
//                                                            		scrollbar1.reset ();
                                                                }
                                                            }, 100
                                                        );
                                                    });
                                                    
                                                    ob_page._preloader (false);
                                                }
                                            }, 100
                                        );
                                    }
                                }
                            }, 100
                        );
                        
                        return;
                    }
                    
                    
                    ob_page._post ({
                        st_action: "account",
                        st_subaction: "login-form"
                    });
                    ob_page.id_interval = window.setInterval (
                        function () {
                            if (ob_page.bo_loaded) {
                                window.clearInterval (ob_page.id_interval);
                                $ ("#div-inner").html (ob_page.ob_output.html);
                                
                                // login
                                $ ("#inputs-login").click (function () {
                                    ob = {
                                        st_action:    "account",
                                        st_subaction: "login",
                                        st_email:     $ ("#input-login-email").val (),
                                        st_password:  $ ("#inputp-login-password").val (),
                                        st_token:     "",
                                        ob_parent:    $ (this)
                                    };
                                    ob_page._post (ob);
                                    ob_page.id_interval = window.setInterval (
                                        function () {
                                            if (ob_page.bo_loaded) {
                                                window.clearInterval (ob_page.id_interval);
                                                
                                                if (ob_page.ob_output.status) {
                                                    $ ("#h4-status-login").html (ob_page.ob_output.status);
                                                    $ ("#h4-status-login").attr ("class", (ob_page.ob_output.error ? "error" : "status"));
                                                    $ ("#h4-status-login").show ();
                                                }
                                                else {
                                                    $ ("#h4-status-login").html ("");
                                                    $ ("#h4-status-login").hide ();
                                                }
                                                
                                                ob_page._preloader (false);
                                                
                                                if (! ob_page.ob_output.error) {
                                                    ar = ob_page.ob_output.html.split (":");
                                                    
                                                    //$.cookie ("email", ar[0]);
                                                    //$.cookie ("token", ar[1]);
                                                    //document.cookie = "email=" + ar[0];
                                                    //alert ($.cookie ("TESTCOOKIE"));
                                                    // reload account panel
                                                    $ ("#li-account a").click ();
                                                }
                                            }
                                        }, 100
                                    );
                                });
                                
                                // register
                                $ ("#inputs-register").click (function () {
                                    //if ($ ("h4:visible").length) {return false;}
                                    ob = {
                                        st_action:    "account",
                                        st_subaction: "register",
                                        st_firstname: $ ("#input-register-firstname").val (),
                                        st_lastname:  $ ("#input-register-lastname").val (),
                                        st_address1:  $ ("#input-register-address1").val (),
                                        st_address2:  $ ("#input-register-address2").val (),
                                        st_province:  $ ("#input-register-province").val (),
                                        st_zip:       $ ("#input-register-zip").val (),
                                        in_country:   $ ("#select-countries").val (),
                                        st_email:     $ ("#input-register-email").val (),
                                        st_password:  $ ("#inputp-register-password").val (),
                                        st_rpassword: $ ("#inputp-register-rpassword").val (),
                                        ob_parent:    $ (this)
                                    };
                                    ob_page._post (ob);
                                    ob_page.id_interval = window.setInterval (
                                        function () {
                                            if (ob_page.bo_loaded) {
                                                window.clearInterval (ob_page.id_interval);
                                                
                                                if (ob_page.ob_output) {
                                                    $ ("#h4-status-register").html (ob_page.ob_output.status);
                                                    $ ("#h4-status-register").attr ("class", (ob_page.ob_output.error ? "error" : "status"));
                                                    $ ("#h4-status-register").show ();
                                                    
                                                    if (! ob_page.ob_output.error) {
                                                        $ ("#div-register p").remove ();
                                                		scrollbar1.reset ();
                                                		scrollbar1.reset ();
                                                    }
                                                    
                                                    ob_page._preloader (false);
                                                }
                                            }
                                        }, 100
                                    );
                                });
                                
                                // password
                                $ ("#inputs-password").click (function () {
                                    //if ($ ("h4:visible").length) {;return false;}
                                    ob = {
                                        st_action:    "account",
                                        st_subaction: "password",
                                        st_email:     $ ("#input-password-email").val (),
                                        ob_parent:    $ (this)
                                    };
                                    ob_page._post (ob);
                                    ob_page.id_interval = window.setInterval (
                                        function () {
                                            if (ob_page.bo_loaded) {
                                                window.clearInterval (ob_page.id_interval);
                                                $ ("#h4-status-password").html (ob_page.ob_output.status);
                                                $ ("#h4-status-password").attr ("class", (ob_page.ob_output.error ? "error" : "status"));
                                                $ ("#h4-status-password").show ();
                                                
                                                ob_page._preloader (false);
                                            }
                                        }, 100
                                    );
                                });
                                
                                ob_page._preloader (false);
                        		scrollbar1.reset ();
                        		scrollbar1.reset ();
                            }
                        }, 100
                    );
        
                }
            }, 100
        );
    });
    
    /*
     Conditions
    */
    
    $ ("#conditions b").click (function () {
    	
    	var conditions = "<b>Terms and conditions</b><br/><br/><b>Polo on Demand</b><br/><br/><b>In using this website you are deemed to have read and agreed to the following terms and conditions.</b><br/><br/>The following terminology applies to these terms and conditions. Privacy statement and disclaimer notice and any or all agreements. “clients”, “You” and “yours” refers to you, the person accessing this website and accepting the companies terms and conditions. “The company”, “ourselves” ,”we” and “us” refers to our company. ”Party”, “Parties”, or “Us”, refers to both the client and ourselves, or either the client or ourselves. All terms refer to the offer, acceptance and consideration of payment necessary to undertake the process of our assistance to the client in the most appropriate manner, whether by formal meetings of a fixed duration, or any other means, for the express purpose of meeting the client’s needs in respect of provision of the company’s stated services/products, in accordance with and subject to, prevailing English law. Any use of the above terminology or other words in the singular, plural, capitalisation and/or he/she or they, are taken as interchangeable and therefore as referring to the same.<br/><br/><b>Privacy statement.</b><br/>We are committed to protecting your privacy.";
    	conditions += " Authorised employees within the company on a need to know basis only use any information collected from individual customers. Parliament has created specific offences for unauthorised actions against computer systems and data. We will investigate any such actions with a view to prosecuting and/or taking civil proceedings to recover damages against those responsible.<br/><br/><br/><b>Confidentiality</b><br/>We are committed to protecting your privacy under the data protection act 1998 and as such, any information concerning the client and their respective Client records may be passed to third parties. However, client records are regarded as confidential and therefore will not be divulged to any third party other than Project video ltd and if legally required to do so to the appropriate authorities. Clients have the right to request sight of and copies of any and all client records we keep, on the proviso that we are given reasonable notice of such a request. Clients are requested to retain copies of any literature issued in relation to the provision of our services. Where appropriate, we shall issue clients with appropriate written information, handouts or copies of records as part of an agreed contract for the benefit of both parties.<br/><br/>";
    	conditions += "<b>We will not sell, share, or rent your personal information to any third party or use your email address for unsolicited mail. Any emails sent by this company will only be in connection with the provision of agreed services and products.</b><br/><br/><b>Disclaimer</b><br/><b>Exclusions and Limitations.</b><br/>The information on the website is provided on an ‘as is’ basis. To the fullest extent permitted by law, this company:<br/><br/><li>excludes all representations and warranties relating to this website and its contents or which is or may be provided by any affiliates or any other third party, including in relation to any inaccuracies or omissions in this website and/or the companies literature and</li><br/><li>excludes all liability for damages arising out of or in connection with your use of this website. This includes, without limitation, direct loss, loss of business or profits ( whether or not the loss of such profits was foreseeable, arose in the normal course of things or you have advised this company of the possibility of such potential loss), damage to your computer, computer software, systems and programmes and the data thereon or any other direct or indirect, consequential and incidental damages.</li><br/><br/>";
    	conditions += "This company does not however exclude liability for death or personal injury caused by it’s negligence. The above exclusions and limitations apply only to the extent permitted by law. None of your statutory rights as a consumer are affected.<br/><br/><b>Payment.</b><br/>Major credit/debit cards are all acceptable methods of payment via paypal. Terms and conditions relating to use of paypal can be read at www.paypal.com. All goods remain the property of the company until paid for in full.<br/><br/><b>Cancellation policy.</b><br/>All monthly subscriptions will be charged for the current month of usage and terminated at the next subscription due date. For all 24 hour memberships no refund will be available.<br/><br/><b>Termination of agreements and refunds policy.</b><br/>Both the client and ourselves have the right to terminate any services agreement for any reason, including the ending of services that are already underway. No refunds shall be offered, where a service is deemed to have begun and is, for all intents and purposes, underway. Any monies that have been paid to us which constitute payment in respect of the provision of unused services, shall be refunded.<br/><br/><b>Availability.</b><br/>";
    	conditions += "The services featured oj this website are available to a worldwide market. All advertising is intended for a UK market. You are solely responsible for evalualitng the fitness for a particular purpose of any downloads, programs and text available through this site. Redistribution or republication of any part of this site or its contents is prohibited, including such by framing or other similar or any other means, without the express written consent of the company. The company does not warrant that the service from this site will be uninterrupted, timely or error free, although it is provided to the best of its ability. By using the service you thereby indemnify this company, its employees, agents and affiliates against any loss or damage, in whatever manner, howsoever caused.<br/><br/><b>Log files.</b><br/>We use IP addresses to analyse trends, administer the site, track user’s movement and gather broad demographic information for aggregate use. IP addresses are not linked to personally identifiable information. Additionally, for systems administration, detecting usage patterns and trouble shooting purposes, our web servers automatically log standard access information including browser type, access times/open mail, URL requested, and referral URL. This information is not shared with third parties and is used only within this company on a need to know basis. Any individually identifiable information related to this data will never be used in anyway different to that stated above without your explicit permission.<br/><br/>";
    	conditions += "<b>Cookies.</b><br/>Like most interactive websites this company’s website (or ISP) uses cookies to enable us to retrieve user details for each visit. Cookies are used in some areas of our site to enable the functionality of this area and ease of use for those people visiting. Some of our affiliate partners may also use cookies.<br/><br/><b>Links to this website.</b><br/>You may not create a link to any page of this website without our prior written consent. If you do create a link to a page of this website you do so at your own risk and the exclusions and limitations set out above will apply to your use of this website by linking to it.<br/><br/><b>Links from this website</b><br/>We do not monitor or review the content of other party’s websites which are linked to from this website. Opinions expressed or material appearing on such websites are not necessarily shared or endorsed by us and should not be regarded as the publisher of such opinions or material. Please be aware that we are not responsible for the privacy practices or content of these sites. We encourage our users to be aware when they leave our site and to read the privacy statements of these sites. You should evaluate the security and trustworthiness of any other site connected to this site or accessed through this site yourself, before disclosing any personal information to them. This company will not accept any responsibility for any loss or damage in whatever manner, howsoever caused, resulting from your disclosure to third parties of personal information.<br/><br/>";
    	conditions += "<b>Copyright notice.</b><br/>Copyright and other relevant intellectual property rights exists on all text relating to the company’s services and the full content of this website.<br/>This company’s logo is a registered trademark of this company in the United Kingdom and other countries. The brand names and specific services of this company featured on this web site are trade marked.<br/><br/><br/><b>Communication</b><br/>We have different email addresses for different queries. These and other contact information can be found on our contacts page on our website or via company stated telephone number.<br/><br/>This company is registered in England and Wales Number:6920016, registered office 113 Anyards Road, Cobham,Surrey,KT11 2LJ<br/><br/><b>Force Majeure</b><br/>Neither party shall be liable to the other for any failure to perform any obligation under any agreement which is due to an event beyond the control of such party including but limited to any Act Of God, terrorism, war, Political insurgence, insurrection, riot, civil unrest, act of civil or military, uprising, earthquake, flood or any other natural or man made eventuality outside of our control, which causes the termination of an agreement or contract entered in to, nor which could have been reasonably foreseen. Any party affected by such event shall forthwith inform the other party of the same and shall use all reasonable endeavours to comply with the terms and conditions of any agreement contained herein.<br/><br/>";
    	conditions += "<b>Waiver</b><br/>Failure of either party to insist upon strict performance of any provision of this or any agreement or the failure of either party to exercise any right or remedy to which it, he or they are entitled hereunder shall not constitute a waiver thereof and shall not cause a diminution of the obligations under this or any agreement. No waiver of any of the provisions of this or any agreement shall be effective unless it is expressly stated to be such and signed by both parties.<br/><br/><b>General</b><br/>The laws of England and Wales govern these terms and conditions. By accessing this website and buying our products you consent to these terms and conditions and to the exclusive jurisdiction of the English courts in all disputes arising out of such access. If any of these terms are deemed invalid or unenforceable for any reason ( including, but limited to the exclusions and limitations set out above) then the invalid or unenforceable provision will be severed from these terms and the remaining terms will continue to apply. Failure of the company to enforce any of the provisions set out in these terms and conditions and any agreement, or failure to exercise any option to terminate, shall not be construed as waiver of such provisions and shall not affect the validity of these terms and conditions or of any agreement or any part thereof, ";
    	conditions += "or the right thereafter to enforce each and every provision. These terms and conditions shall not be amended, modified, varied or supplemented except in writing and signed by duly authorised representatives of the company.<br/><br/><br/><b>Notification of changes</b><br/>The company reserves the right to change these conditions from time to time as it sees fit and your continued use of the site will signify your acceptance of any adjustments to  these terms. If there are any changes to our privacy policy we will announce that thses changes have been made on our home page and on other key pages on our site. If there are any changes in how we use our site customer’s personally identifiable information, notification by email or postal mail will be made to those affected by this change. Any changes to our privacy policy will be posted on our website 30 days prior to these changes taking place. You are therefore advised to re read this statement on a regular basis.<br/><br/><b>These terms and conditions form part of the agreement between the client and ourselves. Your accessing of this website and/or undertaking of a booking or agreement indicates your understanding, agreement to and acceptance, of the disclaimer notice and the full terms and conditions contained herein. Your statutory consumer rights are unaffected.</b><br/><br/>Poloondemand 2009. All right reserved.";
    	
    	$ ("#div-inner").html ( "<div class='container' >" + conditions + "</div>" );
		scrollbar1.reset ();
		scrollbar1.reset ();

 		$ ("#div_menu ul li").each (function () {
            $ ("#div_menu ul li").removeClass ("li_channel_selected");
        });
    	
    });
    
    /**
     * search
     */
    $ ("#li-search").click (function () {
        ob = {
            st_action:    "search",
            st_subaction: "init"
        };
        ob_page._post (ob);
        ob_page.id_interval = window.setInterval (
            function () {
                if (ob_page.bo_loaded) {
                    window.clearInterval (ob_page.id_interval);
                    
                    $ ("#div-inner").html (ob_page.ob_output.html);
                    
                    if (ob_page.ob_output.status) {
                        $ ("#h4-status-search").html (ob_page.ob_output.status);
                        $ ("#h4-status-search").attr ("class", (ob_page.ob_output.error ? "error" : "status"));
                        $ ("#h4-status-search").show ();
                    }
                    else {
                        $ ("#h4-status-search").html ("");
                        $ ("#h4-status-search").hide ();
                    }
                    
                    if (! ob_page.ob_output.error) {
                		scrollbar1.reset ();
                		scrollbar1.reset ();
                		
                    	// search
                    	$ ("#inputs-search").click (function () {
                    	    if (! $ ("#input-search").val ()) return false;
                    	     
                    		eval ("st_reg = /" + $ ("#input-search").val ().toLowerCase () + "/");
                    		var i = 0;
                    		var ar = new Array ();
                    		$ ("node", window._wtv.xml).each (function () {
                    			if ($ (this).children ("nodetype").text () == "VIDEO") {
                    			    
                    				st_id          = $ (this).children ("id").text ();
                    				st_name        = $ (this).children ("element").children ("name").text ();
                    				st_description = $ (this).children ("element").children ("description").text ();
                    				st_transcript  = $ (this).children ("element").children ("transcript").text ();
                    				st_element_id  = $ (this).children ("element").children ("id").text ();
                    				st_bitrate     = $ (this).children ("element").children ("bitrate").text ();
                    				st_videoid     = $ (this).children ("element").children ("videoid").text ();
                    				st_image       = $ (this).children ("element").children ("image").text ();
                    				
                    				
                    				
                    				in_name        = st_name.toLowerCase ().search (st_reg);
                    				in_description = st_description.toLowerCase ().search (st_reg);
                    				in_transcript  = st_transcript.toLowerCase ().search (st_reg);
                    				
                    				if (in_name != -1 || in_description != -1 || in_transcript != -1) {
                    					// found
                    					ar[i++] = {
                    						st_id: st_id,
                    						st_name: st_name,
                    						st_description: st_description,
                    						st_transcript: st_transcript,
                    						st_element_id: st_element_id,
                    						st_bitrate: st_bitrate,
                    						st_videoid: st_videoid,
                    						st_image: st_image
                    					};
                    				}
                    			}
                    		});
                    		
                    		var st = "";
                    		for (var i in ar) {
                    			st += "<li class='li_video' id='li_2_video_" + ar[i].st_id + "'>" +
                    				"<div class='div_image'><a class='a_video' href='#' title='" + ar[i].st_description + "'><img src='videoimgs/" + ((ar[i].st_image)? ar[i].st_image : videoconfig.thumb_image)  + "' alt='' /></a></div>" +
                    				"<div class='div_name'><a class='a_video' href='#' title='" + ar[i].st_description + "'>" + ar[i].st_name + "</a></div>" +
                    				"<div class='div_id'>" + ar[i].st_element_id + "</div>" +
                    				"<div class='div_videoid'>" + ar[i].st_videoid + "</div>" +
                    				"<div class='div_bitrate'>" + ar[i].st_bitrate + "</div>" +
                    				"<div class='div_transcript'>" + ar[i].st_transcript + "</div>" +
                    				"<div class='div_description'>" + ar[i].st_description + "</div>" +
                    			"</li>";
                    		}
                    		
                    		$ ("#div-search-list").html ("<ul id='ul-search-results'>" + st + "</ul>");
                    		
                    		$ ("#ul-search-results").children ("li").click (function () {
                    			var st_video   = $ (this).children (".div_videoid").text ();
                    			var st_bitrate = $ (this).children (".div_bitrate").text ();
                                var in_id      = $ (this).children (".div_id").text ();
                    			
                    			// open video
                    			openVideo ({
                    				  url: videoconfig.videoserver
                    				, file: st_video
                    				, speed: st_bitrate
                    				, live: false
                    				, skin: videoconfig.skin || ''
                    				, slidesinterface: false
                    				, id: in_id
                    			});
                    			
                    			try {
                    				clickVideo ($ (this), "VIDEO");
                    			}
                    			catch (e) {
                    			}
                    		});
                    		
                    		scrollbar1.reset ();
                    		scrollbar1.reset ();
                    	});
                    }
                    
                    ob_page._preloader (false);
                }
            }, 100
        );
    });
	
	/**
	 * carousel
	 */
	var ar = new Array ();
	var i = 0;
	$ ("node", window._wtv.xml).each (function () {
        if ($ (this).parent ("node").children ("element").children ("label").text () == "WHATSNEW") {
			st_id          = $ (this).children ("id").text ();
			st_name        = $ (this).children ("element").children ("name").text ();
			st_description = $ (this).children ("element").children ("description").text ();
			st_transcript  = $ (this).children ("element").children ("transcript").text ();
			st_element_id  = $ (this).children ("element").children ("id").text ();
			st_bitrate     = $ (this).children ("element").children ("bitrate").text ();
			st_videoid     = $ (this).children ("element").children ("videoid").text ();
			st_image       = $ (this).children ("element").children ("image").text ();
			ar[i++] = {
				st_id: st_id,
				st_name: st_name,
				st_description: st_description,
				st_transcript: st_transcript,
				st_element_id: st_element_id,
				st_bitrate: st_bitrate,
				st_videoid: st_videoid,
				st_image: st_image
			};
    	}
	});
	
	st = "";
	for (var i in ar) {
		st += "<li id='li_3_video_" + ar[i].st_id + "'>" +
			"<div class='div_image'><a class='a_video' href='#' title='" + ar[i].st_description + "'><img src='videoimgs/" + ((ar[i].st_image)? ar[i].st_image : videoconfig.thumb_image)  + "' alt='' /></a></div>" +
			"<div class='div_name'><a class='a_video' href='#' title='" + ar[i].st_description + "'>" + ar[i].st_name + "</a></div>" +
			"<div class='div_id'>" + ar[i].st_element_id + "</div>" +
			"<div class='div_videoid'>" + ar[i].st_videoid + "</div>" +
			"<div class='div_bitrate'>" + ar[i].st_bitrate + "</div>" +
			"<div class='div_transcript'>" + ar[i].st_transcript + "</div>" +
			"<div class='div_description'>" + ar[i].st_description + "</div>" +
		"</li>";
	}
	
	$ ("#slides").html ("<ul id='ul-slides' class='jcarousel-skin-tango' >" + st + "</ul>");
	
	$ ("#ul-slides").children ("li").click (function () {
		var st_video   = $ (this).children (".div_videoid").text ();
		var st_bitrate = $ (this).children (".div_bitrate").text ();
        var in_id      = $ (this).children (".div_id").text ();
		
		// open video
		openVideo ({
			  url: videoconfig.videoserver
			, file: st_video
			, speed: st_bitrate
			, live: false
			, skin: videoconfig.skin || ''
			, slidesinterface: false
			, id: in_id
		});
		
		try {
			clickVideo ($ (this), "VIDEO");
		}
		catch (e) {
		}
	});
	
	$ ("#ul-slides").jcarousel();
	
	$ ("#ul-slides").children ("li").hover (function () {
		var st_description   = $ (this).children (".div_description").text ();
		$("#slidetitle").html( st_description );
		},
		function () {
			$("#slidetitle").html( "" );
		}
	);
	
}

/**
 * clickVideo
 *
 * @param object ob_li clicked li element
 * @param string st_type VIDEO or LIVE
 */
function clickVideo (ob_li, st_type)
{
	
	//$ ("#div_channelname").html ( 'CHANNEL: ' + $(".li_channel_selected .div_name:eq(0)").text ());
	//$ (".li_video").css ({background: "#000"});
	
	$("div#div_videos li").removeClass("selected");
	$(ob_li).addClass("selected");
	
	// change program name
	$ ("#span_program").html (ob_li.children (".div_name").text ());
	
	// change transcript
	$ ("#video_info>.Scroller-Container").html (ob_li.children (".div_transcript").html ());
	


	
}

/**
 * clickCategory
 *
 * @param object ob_li clicked li element
 */
function clickCategory (ob_li)
{
	
	$( "div#div_submenu li" ).removeClass("selected");
	
	$( ob_li ).addClass("selected");

	// hides all and the show the clicked category	
	var vis = ob_li.children(".ul_category").is(':visible');
	$("#div_videos ul.ul_category").hide("fast");
	if ( !vis )  ob_li.children(".ul_category").show("normal", function() {scrollbar1.reset();scrollbar1.reset();} );
	
	scrollbar1.reset();
	scrollbar1.reset();
}

/**
 * clickPlaylist
 *
 * @param object ob_li clicked li element
 */
function clickPlaylist (ob_li)
{
}

/**
 * clickChannel
 *
 * @param object ob_li clicked li element
 */
function clickChannel (ob_li)
{
}

/**
 * streamInfo
 *
 * @param object ob
 */
function streamInfo (ob)
{
	$.post(
		  ob.playlist
		, ""
		, function (data) {
			window._wtv.playlistXML = data;
			window._wtv.playlistXMLLoaded = true;
		}
		, "xml"
	);
	
	intval = window.setInterval (
		function () {
			if (window._wtv.playlistXMLLoaded) {
				
				// get video
				$.each (
					  $ ("data", window._wtv.playlistXML).children (), function (i) {
					  	if ($ (this).get (0).nodeName == "video"
					  	&& $ (this).children ("vid").text () == ob.videoid) {
					  		$ (this).children ().each (function () {
					  			switch ($ (this).get (0).nodeName) {
					  				case "transcript":
					  					$ ("#div_information div#pane3").html ($ (this).text ());
					  					break;
					  				case "title":
					  					$ ("#span_program").html ($ (this).text ());
					  					break;
					  				case "":
					  					break;
					  			}
					  		});
					  	}
					}
				);
				
				window.clearInterval (intval);
			}
		},
		100
	);
}


/**
 * custom page object
 */
ob_page = {
    bo_loaded: false,
    ob_output: {},
    id_interval: null,
    
    _init: function ()
    {
    },
    
    _post: function (ob)
    {
        if (! ob) return false;
        
        this.bo_loaded = false;
        
        this._preloader (true);
        
        $.post (
            "action.php",
            ob,
            function (st) {
                ob_page.ob_output = unserialize (st);
                ob_page.bo_loaded = true;
            }
        );
    },
    
    _paypal: function ()
    {
        $ ("#inputh-item_name").val ("Access to Polo on Demand for " + ($ ("input[name=amount]:checked").val () == _PRICE_30 ? "30 days" : "24 hours") + "");
        
        ob_page._post ({
            st_action:    "options",
            st_subaction: "insert",
            st_email:     cookie_email,
            st_token:     cookie_token,
            st_password:  "",
            in_period:    $ ("input[name=amount]:checked").val () == _PRICE_30 ? 2 : 1
        });
        
        ob_page.id_interval = window.setInterval (
            function () {
                if (ob_page.bo_loaded) {
                    window.clearInterval (ob_page.id_interval);
                    
                    ob_page._preloader ($ ("#div-paypal"), false);
                    
                    if (ob_page.ob_output.error) {
                        $ ("#h4-status-paypal").html (ob_page.ob_output.status);
                        $ ("#h4-status-paypal").attr ("class", "error");
                        $ ("#h4-status-paypal").show ();
                    }
                    else {
                        //var st = $ ("#inputh-return").val ();
                        $ ("#inputh-custom").val (ob_page.ob_output.html);
                        $ ("#form-paypal").submit ();
                    }
                }
            }, 100
        );
        
        return false;
    },
    
    _reset: function (st)
    {
        $ (st).hide ();
        var ob_parent = $ (st).parents ("div");
        this._preloader (false);
    },
    
    _preloader: function (bo)
    {
        $ ("#div-preloader").css ({
            width:    bo ? ($ ("#div_container").width ()) : 0,
            height:   bo ? ($ ("#div_container").height ()) : 0,
//            left:     bo ? ($ ("#div_container").offset ().left - 485) : 0,
//            top:      bo ? ($ ("#div_container").offset ().top) : 0,
            left: 0,
            top: 0,
            position: "absolute",
            opacity:  0
        });
        
        //c ($ ("#div_container").offset ().left);
    }
}

function c (st) {try {console.log (st);} catch (e) {}}
function fc (ob) {for (var i in ob) {c (i + " " + ob[i]);}}

